n=5
for i in {1..$[n]}
do
echo $i
done
it gives:
{1..5}
But I think it should output:
1
2
3
4
5
Why it gives such a strange output?
n=5
for i in {1..$[n]}
do
echo $i
done
it gives:
{1..5}
But I think it should output:
1
2
3
4
5
Why it gives such a strange output?
That is almost a riddle. The expansion of the braces is being done prior to the variable expansion. The bash beginners guide has some good detail on expansion There are a brazillion ways to do this in bash. You could start with:
n=5
for i in $(eval echo {1..$n})
do
echo $i
done