Re: [Help-bash] How to safely work on files/dirs with .
From:
Stephane Chazelas
Subject:
Re: [Help-bash] How to safely work on files/dirs with .
Date:
Mon, 14 Mar 2016 14:20:15 +0000
User-agent:
Mutt/1.5.21 (2010-09-15)
2016-03-14 08:40:54 -0400, Greg Wooledge:
[...]
> > Note that it misses files like ..foo or ... (you'd need to add
> > an extra ..?* glob for them).
> >
> > zsh, pdksh (and derivatives, actually derivatives of the Forsyth
> > shell which pdksh is based on) and fish expansions never
> > include "." nor ".." in their glob expansions, so you can use .*
> > reliably in those shells.
>
> For completeness, and to get things back on topic for help-bash,
> bash includes a shopt named "dotglob" which makes * match files
> beginning with dot.
Note that it doesn't prevent the expansion of . and .. in a .*
glob (which was the point being discussed here):
$ bash -O dotglob -c 'echo .*'
. .. .a
Setting GLOBIGNORE in bash also enables dotglob and then
excludes . and .., but only for .<anything> globs:
$ bash -c 'GLOBIGNORE=:; echo .*'
.a
$ bash -c 'GLOBIGNORE=:; echo ./.*'
./. ./.. ./.a
--
Stephane