0

Bash:

$: echo {1..5}
1 2 3 4 5
$: n=5
$: echo {1..$n}
{1..$n}

I can't figure out how to use this syntax to work on variables. I'm sure this answer is very simple, but syntax like this is very hard to "just Google".

GreenFox
  • 445
  • 1
  • 3
  • 12
  • One more reason to use zsh. – Kevin Sep 28 '17 at 19:15
  • This is [BashPitfalls #33](http://mywiki.wooledge.org/BashPitfalls#for_i_in_.7B1...24n.7D). – Charles Duffy Sep 28 '17 at 20:56
  • @Kevin, one reason *not* to use zsh is that after doing so it's hard to write correct POSIX-baseline code, having finger-memory and idioms from a much more permissive language. Which is to say -- I'd argue that it's better that if you're going to write a incompatible language, it shouldn't *look like* an older one that's still in widespread use to avoid finger-memory cross-pollination, *especially* when there isn't compile-time checking to detect such issues. – Charles Duffy Sep 28 '17 at 20:56
  • (Contrast with, say, [scsh](https://scsh.net/) -- beautiful, clean language, but doesn't *try* to look like POSIX shell languages). – Charles Duffy Sep 28 '17 at 20:59

0 Answers0