Javareak
Javareak

Reputation: 31

Understanding bash brace expansion

I read this post: https://superuser.com/questions/304807/brace-expansion-run-several-commands-instead-of-expanding-on-one-line and tried its eval echo way of expansion. Why are the two commands below different?


Command 1:

$ eval echo\ {a,b,c}\;

Result 1:

a
b
c

Command 2:

$ eval echo\ {a,b,c} \;

Result 2:

a echo b echo c

Upvotes: 1

Views: 191

Answers (1)

William Pursell
William Pursell

Reputation: 212574

The eval is just confusing things, so get rid of it:

$ echo echo\ {a,b,c}\;
echo a; echo b; echo c;
$ echo echo\ {a,b,c} \;
echo a echo b echo c ;

That should make it obvious what's happening. In the first case, eval executes three different echo commands. In the second, it only evaluates one command that takes the string 'a echo b echo c' as an argument.

Upvotes: 5

Related Questions