0

Hi,

for i in 84 85 86 87 88 89 90 91 92; do ./runCleanup Session 11${i}; done

i tried as we do in perl like for i in 84..92; do ./runCleanup Session 11${i}; done


But its showing error.

what is the solution.

Thanks,
Deepak

3
Contributors
4
Replies
7
Views
6 Years
Discussion Span
Last Post by masijade
1
set i=84
while [ $i <= 92 ]
do
  # whatever
  i=$(($i + 1))
done

or stick with the first version. What you don't seem to understand is that ".." is an operator (just like "+" is an operator) defined in Perl. It is, as you can see above, not available in Shell. It is a Perl language feature.

Edited by masijade: n/a

Votes + Comments
Thanks for the ans
0

Hi,

for i in 84 85 86 87 88 89 90 91 92; do ./runCleanup Session 11${i}; done

i tried as we do in perl like for i in 84..92; do ./runCleanup Session 11${i}; done


But its showing error.

what is the solution.

Thanks,
Deepak

You are just missing the expansion brackets.

for i in {84..92}; do
  echo $i
done

Concerning the previous posted example

while [ $i <= 92 ]

Not a good idea. The `[' should not be use for arithmetic operation. `<=' are operators for strings. They might work; it will fail when least expected.

There is already a facility for that.

while (( $i <= 92 ))
do
     echo $i
     let ++i
done
0

Right, I believe however that simply using -lt instead of <= also works as expected.

Although I must say i did not know about {x .. y}, you learn something new everyday.

Edited by masijade: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.