0

How to receive command line argument in shell script for loop? e.g

vim batch_echo  
for i in {1..$1}; do echo $i; done

sh batch_echo 3
{1..3}

but if change to seq, it's ok

for i in `seq 1 $1`; do echo $i; done

sh batch_echo 3
1
2
3

so why {1..$1} cannot work?

zhuguowei
  • 8,401
  • 16
  • 70
  • 106

1 Answers1

0

Just like bash, I think it's because brace expansion occurs before expansion of variables. I recommend you to go check: http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion . Let me know if that helped or not.

Hope I could help.

nunovarela
  • 26
  • 8