[Linux-disciples] Portability and `ls`

Chung-chieh Shan ccshan at post.harvard.edu
Thu Feb 9 00:14:22 EST 2006


On 2006-02-08T14:49:03-0500, Adam Rosi-Kessel wrote:
> Stephen R Laniel wrote:
> > for i in dirName/*
> > Is there any reason to use the earlier syntax?
> 
> One guess... The * syntax might be subject to globbing vicissitudes. I don't
> think dirName/* is always going to give the same result, depending on shopt
> settings.

Actually, * is preferred over `ls`, due to globbing vicissitudes when we
have funny characters like spaces and newlines in file names:

    $ mkdir foo
    $ cd foo
    $ echo >"1 2"
    $ echo >"3
    > 4"
    $ for i in *; do echo "[$i]"; done
    [1 2]
    [3
    4]
    $ for i in `ls`; do echo "[$i]"; done
    [1]
    [2]
    [3]
    [4]
    $ 

-- 
Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
http://bash.org/?454203
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bostoncoop.net/pipermail/linux-disciples/attachments/20060209/f1361797/attachment.pgp


More information about the Linux-disciples mailing list