foo-bar-{baz,quux}.txt = foo-bar-baz.txt
foo-bar-quux.txt foo-bar-{baz,quux}.txt = foo-bar-baz.txt
foo-bar-quux.txt> Expansion is performed on the command line after it has been split into words. There are seven kinds of expansion performed: brace expansion, tilde expansion, parameter and variable expansion, command substitution, arithmetic expansion, word splitting, and pathname expansion.
That's not to say it's POSIX-compliant--I have no idea whether it is. But it definitely isn't grouped in with pathname expansion. bash does have an option to disable brace expansion, but it's not toggled by `--posix`, which leads me to believe it might be POSIX-compliant.
I thought that was implied in my post, but perhaps I should have made it explicit.
> That's not to say it's POSIX-compliant--I have no idea whether it is
I didn't know one way or another, but since you brought it up, it looks like it probably is not compliant. See, e.g., this argument that `echo {1,2}` must print '{1,2}' because POSIX doesn't require '{1,2}' to be quoted: https://www.austingroupbugs.net/view.php?id=1193
Brace expansion is a nearly universally supported extension, though, so I doubt it's a real problem. And the above link proposes fixing the standard to make the extension compliant.
$ echo {A,B}
A B
$ echo {A,B}{C,D}
AC AD BC BD
$ echo {A,B}{C,D}{E,F}
ACE ACF ADE ADF BCE BCF BDE BDF$ echo {0..19}
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
$ echo {00..19}
00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
$echo {A..D}
A B C D
$ echo `seq 0 19`
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
(the second doesn't work on older versions of bash, like macos)
$ perl -le 'print join(" ", "00".."20")' 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20
use File::Glob ':bsd_glob';Thanks for the heads up.
Too bad it's not portable, but I guess this is mainly useful in an interactive shell.
I mostly use #!/usr/bin/env sh, so my scripts will remain free of shell Cartesian products and other brace expansions.
mv foo-bar-{baz,quux}.txt
becomes mv foo-bar-baz.txt foo-bar-quux.txtUnlike *, ? [a-z] ...