I wanted to write a script to print 10 number using while loop. I tried the following code
#!/bin/sh
i=0
while [ $i -lt 10 ]
do
echo "$i"
i='expr $i + 1'
done
but I am getting the following error
sh: $i: unknown operand
can anyone explain me why its raising error?
`, not single quotes,', around the righthand side of youri=assignment. (Or even better,$(...), the modern alternative to backticks.)exprat all. POSIX-standardized math syntax isi=$(( i + 1 )), whereas the bash-extended approach is simply(( ++i ))expr,let,$[ ... ], and various other artifacts of antiquity. (well --exprisn't covered there, but that's because it isn't even part of bash at all; when you useexprin bash, it runs a completely separate program like/usr/bin/expr, not part of your shell)