Your two errors are caused by:
until [$MY_VAR = 0]MY_VAR = $(expr $MY_VAR - 1)
[I used $ () instead of backticks because I could not get backlinks in the code section]
The first problem is the lack of spaces around the square brackets - at both ends. The shell looks for the command [6 (after the expansion of $MY_VAR ) instead of [ (see /usr/bin/[ - this is actually a program). You should also use -eq to do numerical comparisons. = should work fine here, but leading zeros can disrupt the string comparison where the numerical comparison will be performed:
until [ "$MY_VAR" -eq 0 ]
Second problem: you have spaces in the variable assignment. When you write MY_VAR = ... , the shell looks for the command MY_VAR . Instead, write as:
MY_VAR=`expr $MY_VAR - 1`
These answers directly answer your questions, but you should study Dennis Williamson's answer for a better way to do this.
source share