0

I am trying to do a loop similar to this basic one:

storage-33:~#  echo {a..z}           
a b c d e f g h i j k l m n o p q r s t u v w x y z

However I have two variables I set on my script called $first_sd and $last_sd

I have been unsuccessful when running it on my shell. The behaviour is not the loop from A to Z I expected. Its actually not doing the loop at all, do I need to convert my variable or is there a trick to make this work? See my bad example here of what I am trying to do (this does not work)

storage-33:~# for i in {$first_sd..$last_sd}; do echo HI $i; done
HI {a..h}

Thanks!

user2864740
  • 60,010
  • 15
  • 145
  • 220
Giovanni
  • 3
  • 1
  • 1
    Related (issue is 2nd level evaluation in both cases): http://stackoverflow.com/questions/10683349/forcing-bash-to-expand-variables-in-a-string-loaded-from-a-file – user2864740 Sep 09 '14 at 23:47

2 Answers2

1

You can use eval remembering to escape the appropriate characters:

eval "for i in {$first_sd..$last_sd}; do echo HI \$i; done"
Miguel
  • 7,497
  • 2
  • 27
  • 46
1

Use eval

for i in $(eval echo "{$first_sd..$last_sd}"); do echo HI $i; done
Amit
  • 19,780
  • 6
  • 46
  • 54