3

I'm writing a script which needs to use the shell's brace expansion, but nothing I've tried works. For (a contrived) instance, say I have a variable containing the string

thing{01..02}

and I (obviously) want to expand it to

thing01 thing02  

from inside the script, how can I do that?

(For anyone who assumes this is a duplicate of this other question, please read them more carefully. That question is regarding working from the shell, not a shell script, and doesn't require the ability to expand arbitrary expressions.)

Community
  • 1
  • 1
iconoclast
  • 21,213
  • 15
  • 102
  • 138

2 Answers2

2

Make sure that braceexpand is turned on with set -o braceexpand.

Mark Reed
  • 91,912
  • 16
  • 138
  • 175
  • When I wrote it in bash script, I got `set: 2: Illegal option -o braceexpand` – user13107 Apr 05 '13 at 05:02
  • 1
    It seems problem was because I was running it as `sh script` instead of `bash script`. Also added that line in bashrc instead of script. – user13107 Apr 05 '13 at 05:07
2
$ echo thing{01,02}

thing01 thing02
Shizzmo
  • 16,231
  • 3
  • 23
  • 15