Thanks to everyone for this.
gavin at fiachra gavin> shopt -u nullglob
was what I wanted.
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
> "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
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!