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

Recommended Answers

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, …

Jump to Post

All 4 Replies

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.

commented: Thanks for the ans +2

Hi masijade,

Thanks..

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.