unix/ShellGlobTrick written at 00:18:03; Add Comment
A Unix shell glob trick
This is the kind of trick where first I show the trick and then I explain it:
$ touch a-b; mkdir a-c $ cd a-* sh: cd: a-b: Not a directory $ cd a-*/ $ pwd /tmp/a-c
(This is also a good illustration of quality of implementation in error
handling. A number of non-bash Bourne shells will report things like
What this does is use a trick to pick the directory out of an otherwise
ambiguous wildcard expansion. When there's a
(The usual case for me is that I have just unpacked
Reading very carefully between the lines, I think that this behavior is
required by the SUS. In general
a shell might as well support this, since you can always write the
wildcard as '
A closely related trick can be used to find all of the subdirectories
in your current directory (or in general, somewhere): '
(Ironically, bash gets this one right, and I believe that getting it right is the SUS-required behavior.)
* * *
Atom feeds are available; see the bottom of most pages.