Shell expansion of * and hidden files
Nifty Hat Mitch
mitch48 at sbcglobal.net
Sun Jul 25 06:54:06 UTC 2004
On Fri, Jul 23, 2004 at 08:36:59AM -0400, Robert P. J. Day wrote:
> >Robert P. J. Day wrote:
> >>it's a popular puzzle to come up with a glob that matches all
> >>hidden thingies, without matching "." or "..". and the solution is
> >>...
> >>
> >>$ echo .[!.]*
>
> the puzzle would be to try to come up with a *single* RE that would
> work in all cases. anyone? anyone? beuller?
Try this....
$ pwd
/tmp/g1
$ tar -cvf /tmp/tball ../g1
tar: Member names contain `..' ## this is a warning
--- snip ---
$ tar -xPvf /tmp/tball ## -P because of warning.
../g1/
../g1/.a
--- snip ---
or use "find . " to generate the file list.
A better solution is to cd ../
$ pwd
/tmp/g1
$ cd ..
$ tar -cvf /tmp/tball g1
By design * will not match dot files. Consider the damage that
"rm -r * " would do if * included ../ !!!! We expect recursion
to go down not both ways.
It can get very tangled. Study the man page for your
shell of choice with care. This is from "man bash":
"The GLOBIGNORE shell variable may be used to restrict the set
of file names matching a pattern. If GLOBIGNORE is set, each
matching file name that also matches one of the patterns in
GLOBIGNORE is removed from the list of matches. The file names
‘‘.’’ and ‘‘..’’ are always ignored, even when
GLOBIGNORE is set. However, setting GLOBIGNORE has the effect
of enabling the dotglob shell option, so all other file names
beginning with a ‘‘.’’ will match. To get the old behavior
of ignoring file names beginning with a ‘‘.’’, make ‘‘.*’’
one of the patterns in GLOBIGNORE. The dotglob option is
disabled when GLOBIGNORE is unset."
--
T o m M i t c h e l l
/dev/dull where insight begins.
More information about the users
mailing list