Hello,
I have a question on shell scripting korn shell.
I have a small script as follows
for ((i=0; i <= 5 ; i++))
do
echo "Welcome $i times"
done
As I run this script I get the following error
./test.sh: 0403-057 Syntax error at line 1 : `(' is not expected.
Whatever I change the same error appears again and again.
Please tell me if this kind of loop is supported in ksh and bash since it gives the same error in both the shells.
Hello,
Thanks a lot.
I knew that I could do it with while and also by giving the numbers in for loop.
I actually want to know if I can do it the way that I have specified.
Your code works fine on bash. But on ksh it doesnt.
The man pages spell it out clearly.
man bash says
Code:
for (( expr1 ; expr2 ; expr3 )) ; do list ; done
First, the arithmetic expression expr1 is evaluated according to
the rules described below under ARITHMETIC EVALUATION. The
arithmetic expression expr2 is then evaluated repeatedly until
it evaluates to zero. Each time expr2 evaluates to a non-zero
value, list is executed and the arithmetic expression expr3 is
evaluated. If any expression is omitted, it behaves as if it
evaluates to 1. The return value is the exit status of the last
command in list that is executed, or false if any of the expres-
sions is invalid.