This code...
#!/bin/bash
cond=10;
for i in {1..$cond}
do
echo hello;
done
...just drives me crazy. This prints only one 'hello', as in i
there is {1..10}
.
#!/bin/bash
cond=10;
for i in {1..10}
do
echo hello;
done
prints 10x hello, which is desired. How to put the variable into the condition? I tried different approaches, none of them worked. What a easy task though.. Thank you in advance.
This will work:
cond=10;
for ((i=0;i<=$cond;i++));
do
echo hello;
done
for
, but somehow I missed the most important one. Thank you - tsusanka 2012-04-04 21:57
for
condition, it's not necessary to say $cond
. cond
by itself works fine too - FatalError 2012-04-04 22:20
Apart from the classic loop already answered, you can use some magic too:
#!/bin/bash
cond=10
for i in $(eval "echo {1..$cond}")
do
echo hello
done
But, of course, is harder to read.
$( seq "$cond" )
instead - nosid 2012-04-04 21:53