Hi all ,
I am having problem related to FOR loop
for i in [1..9]
do
echo $i
done
Noew the above code should give me result as
1
2
--- upto
9
But instead it gives me result as 1..9.
Please Help ..
Hi all ,
I am having problem related to FOR loop
for i in [1..9]
do
echo $i
done
Noew the above code should give me result as
1
2
--- upto
9
But instead it gives me result as 1..9.
Please Help ..
Hi,
Your problem is that you are not running any loop ....., you just set the string [1..9] into i and print it to the screen,
For what you want to do u need the following:
for (( i = 0 ; i <= 9; i++ ))
do
echo $i
done
When you use:
for x in 1 2 3 4
It takes the first param and set it to x,
after that it runs into 2nd param and so on till it finish read all params.
At yours case u wrote
for i in [1..9] - it act like [1..9] is the first param so it set the whole string into i, and since there is nothing after [1..9] it finish the loop after one run.
in case u insist to ust the "for i in ...." format you must enter the values like that:
1 2 3 4 5 6 7 8 9
or to create a list file containing all the params u want to run
and than u can write:
for i in $file
what shell is that? Looks like bash.
#!/bin/ksh
typeset -i i=1
while (( i <= 9 ))
do
echo "${i}"
(( i += 1 ))
done