[ILUG] ls behaviour
Gavin McCullagh
gavin at fiachra.ucd.ie
Mon Jan 28 13:34:14 GMT 2002
Thanks to everyone for this.
gavin at fiachra gavin> shopt -u nullglob
was what I wanted.
Gavin
On Mon, 28 Jan 2002, John Tobin wrote:
> On Mon, Jan 28, 2002 at 11:36:21AM +0000, Gavin McCullagh wrote:
> ?
> ? Hi all,
> ?
> ? if I do
> ?
> ? ls lattice_*.dat
> ?
> ? In the normal way I get back everything which matches that pattern. Great.
> ? However, on the occasion that nothing matches it why do I get a full listing of
> ? the directory? Why don't I get an empty list or file not found or
> ? something?
>
> It depends on what arguments ls is given - without an argument you get
> the directory listing. If bash's "nullglob" option is set and no
> matches are found then "lattice_*.dat" is NOT given as an argument to
> ls. If it isn't set "lattice_*.dat" will be given to ls and you'll get
> the file not found error message. "shopt" will tell you whether it's
> set or not.
>
> ? it's particularly irritating when you do something like
> ?
> ? for i in `ls lattice_*.dat`
>
> for file in lattice_*.dat; do . . .
> will do what you want.
>
> ? do
> ? rm $i
> ? done
> ?
> ? and everything else gets deleted if there isn't a match of lattice_*.dat
> ?
> ? It just doesn't seem very logical to me.
> ?
> ? Gavin
>
> --
> John
> "That would preempt a bunch of problems involved in trying to reconstruct
> exactly how the Perl 5 parser thinks, which nobody entirely understands."
> Larry Wall, 2001/04/20, perl6-language at perl.org
> "Finger to spiritual emptiness underlying everything." -- How a Japanese C
> manual referred to a "pointer to void".
>
> --
> Irish Linux Users' Group: ilug at linux.ie
> http://www.linux.ie/mailman/listinfo/ilug for (un)subscription information.
> List maintainer: listmaster at linux.ie
More information about the ILUG
mailing list