Shell scripting – updating a file holding a counter

[bash]counter=`cat /tmp/counter` ; echo "$counter+1" | bc > /tmp/counter[/bash]

note that loading the /tmp/counter into the variable is a necessary indirection, the following:

[bash]echo "`cat /tmp/counter`+1" | bc > /tmp/counter[/bash]

would not work as the output redirection gets triggered before the cat gets a chance to happen, so the file is emptied too early.