My bash scripts has a variable $c which is called within a sed-line, directly followed by another parameter - and bash (actually fairly logical) seems to think that the other parameter belong to the variable name, rendering it useless/empty.

stupid, stupid me. inserting one line into the other did the trick: sed -n "$(printf "%02d" $(echo "$i+1"|bc))q;d" /var/www/playlisten.txt|cut -c 4- sorry for bothering any of you... ;)
–
ChristianJun 29 '11 at 10:38

I should also mention that, if performance is important to you, you want to try and minimise how many external processes (like bc) you run to do your task. Forking and exec'ing are not cost-free actions and you'll run much faster if you get bash to do most of the work itself for short lived tasks.

By short-lived I mean things like adding one to a variable. Obviously if you want to do a big job like sed an entire file, you're better off doing that in a dedicated external tool but bash provides quite a bit of power to replace expensive operations like i=$(expr $i + 1) or i=$(echo "$i+1"|bc).

A bash loop can be done thus with the increment and other calculations being handled without external processes: