This question already has an answer here:
I am trying to pass the argument as max limit for the for loop like this:
#!/bin/bash
for i in {1..$1}
do
echo $i
done
This however returns {1..2}
when called with argument 2
, instead of executing the script and giving me
1
2
...or in the unlikely event that you really just want sequential numbers:
:-)
This will cycle through all true arguments (a.k.a. "testo mesto" is one argument)
OR
Variable substitutions are not done inside of curly braces. You can use fixed numbers but not variables.
Try one of these alternatives:
As well as John Kugelman's solution, you can use
eval
like this:Or, if $1 is 10, then:
You could also use some variants on:
Or:
That uses process substitution.