I've got the following script:

for i in `echo $FOOS` do
echo bar

Now I (think I) get the idea that the brace expansion only works with literals - hence the echo - but all this seems to do is print just one bar to the console. Why (is string/brace expansion not working)?

What I'd expect to happen is:

  1. Assign the string (foo{1..5}) representing an expansion to variable FOOS
  2. substitute $FOOS, so I've basically got for i in 'echo foo{1..5}' do (looks like I can't escape back-ticks here)
  3. execute echo, so I now have for i in foo1 foo2 foo3 foo4 foo5 do
  4. execute for, printing bar five times to the console output
  5. Not get just one bar printed on screen as the only output :-)
  • Your first line doesn't work. $ FOOS = foo{1..5} FOOS: command not found. Please fix and provide the script exactly as is. – Mikel Oct 27 '15 at 18:32
  • 1
    paste your script onto shellcheck.net and click the arrow. – Arthur2e5 Oct 27 '15 at 18:49


FOO=$(echo foo{1..5})

but better is to use an array



echo ${FOO[*]}


for i in {1..5}
    echo bar


for i in $(seq 5)
    echo bar
| improve this answer | |
  • 1
    Just use FOO=( {1..5} )。 – Arthur2e5 Oct 27 '15 at 21:04
  • What am I doing wrong? v=$( echo {1,20{0..3}} ); echo $v yields 1 200 201 202 203 yet v=( {1,20{0..3}} ); echo $v yields only 1. Answer: Use echo ${v[*]}! – Giszmo Nov 9 '19 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.