(( COUNT++ )) -> "COUNT++: not found" in shell script (( COUNT++ )) -> "COUNT++: not found" in shell script shell shell

(( COUNT++ )) -> "COUNT++: not found" in shell script


You probably want #!/bin/bash rather than #!/bin/sh at the top if you want to use bash-specific operations.

Your script does work fine here on my Mac, where sh is really just bash. If your sh is a real one you might not be so lucky.


(( )) would be a nested subshell (two of them, in fact) with an invocation of a command COUNT++. You want the $(( )) arithmetic substitution mechanism; but that will actually substitute, so you either want to hide it in a comment or use an increment that involves a substitution.

: $(( COUNT++ )) # : is a shell comment

or

COUNT=$(( $COUNT + 1 ))


#!/bin/bashCOUNT=0;while [ $COUNT -le 9 ] ; do sleep 1; (( COUNT++ )) ; echo $COUNT ; done

It's a better way to write this script. And I recommend you to run your script as follow:
./script.sh
or
bash ./script.sh

If you don't have bash, use this way:

#!/bin/shENV=1while [ $ENV -le 10 ]dosleep 1echo $ENVENV=`expr $ENV + 1`done