[ILUG] ls behaviour
John Tobin
tobinjt at netsoc.tcd.ie
Mon Jan 28 12:07:16 GMT 2002
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".
More information about the ILUG
mailing list