It's a sentinel. You can't teach an old dog new tricks, so when I start being able to learn new things, I'll know I'm entering my second childhood.
For years, I used square brackets to match filenames. Now, I use the newer, Berkeley-esque, curlies more often.
$ echo x.[ab]They're different. For curlies, order counts:
x.a x.b
$ echo x.{a,b}
x.a x.b
$ echo x.[ba]Also, x.[ba] must match something.
x.a x.b
$ echo x.{b,a}
x.b x.a
$ mkdir /tmp/FOO; cd /tmp/FOOThey're conceptually different. While square brackets are a file-name-match operation, curlies are text-substitution. When you use square brackets, you're asking for existing files that match the pattern; when you use curlies, it's a typing shorthand that the shell expands for you before it does anything else.
$ ls # nothing there
$ touch x.[ba]
$ ls
x.[ba] # one file!
$ rm -f *
$ touch x.{b,a}
$ ls
x.a x.b
The items can nest, and they don't even have to have anything in them.
$ echo x{,a,b{s,t}}Curly-expansion is officially called brace expansion, and square-bracket expansion is part of pathname expansion, or (more commonly) globbing.
x xa xbs xbt
No comments:
Post a Comment