Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You probably have to wait for David.H to look at this, but I believe it is a subtle exception. The exception being that without a comma separated list the braces are interpreted literally.
I found this by doing the following:
Code:
$ echo c{a{r,t,n},}s
cars cats cans cs
So as the man page says, {} is used to denote a list, so with the absence of a list I would guess it reverts to literal braces:
Code:
{ list; }
list is simply executed in the current shell environment. list must be terminated with a newline or semicolon. This is known as a group command. The return status is the exit status of list. Note that unlike the
metacharacters ( and ), { and } are reserved words and must occur where a reserved word is permitted to be recognized. Since they do not cause a word break, they must be separated from list by whitespace or another
shell metacharacter.
There must be at least one comma or sequence expression.
Quote:
A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged.
Perhaps the code above does work in some other shell like zsh?
But I think Beryllos has found the key to it in bash. A brace expansion can only be used inside another if it's completely contained inside a list sub-entry. It looks like your book is wrong.
It appears that bash is reading it with the following three parts, with only the middle part being a valid brace expansion:
Brace expansion is only available in some advanced shells like bash, ksh, and probably zsh. It won't work in strictly posix-based shells like dash.
/bin/sh is your system's posix-supporting shell, which is usually a symlink to another interpreter like bash or dash. So it may work or it may not, depending on what that link is.
And we've already explained the problems with the above line in bash (it does work, it just doesn't work as expected by the OP).
But it is interesting to see that it apparently also works in c-shell environments, and apparently works as expected.
Last edited by David the H.; 06-04-2013 at 03:28 PM.
Even more interesting stuff to learn! I guess bash originally tried to emulate the csh style, but later went its own way for some reason.
Incidentally, I made an error in my last post. Posix does have the "{a,b,c}" list style of expansion, but it does not support the "{a..z}" range style.
To reiterate what was stated in post #3 from June 2013 this behaviour is clearly described in the Brace Expansion documentation:
Quote:
Originally Posted by https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html
Brace expansions may be nested.
...
A correctly-formed brace expansion must contain unquoted opening and closing braces, and at least one unquoted comma or a valid sequence expression. Any incorrectly formed brace expansion is left unchanged.
Without a comma, and without a sequence expression {INTEGER..INTEGER}, the outer expansion is incorrectly formed and thus should be left unchanged.
If someone feels they have found a bug in a supported version of Bash, they should report it to GNU on the Bash bug mailing list, though I'm not sure 4.3 is supported.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.