[plug] word splitting

James Devenish devenish at guild.uwa.edu.au
Wed Nov 17 15:18:27 WST 2004


In message <1100675119.886.65.camel at vaio>
on Wed, Nov 17, 2004 at 03:05:19PM +0800, Ryan wrote:
> On Wed, 2004-11-17 at 15:01, gavan at iinet.net.au wrote:
> > I have a question with what I know will be an easy answer, but I can't for the 
> > life of me find it anywhere:
> > How do I disable word-splitting in a bash script?
> > Using the following script:
> 
> Double quote the filename:
> 
> > for img in `ls *.jpg`
> 
> for img in ` ls "*.jpg"`

?? That shouldn't work unless you have turned on shell-specific options
to make it work. Also, Gavan, realise that `ls` prints multiple files
per line in its default interactive mode, so it is somewhat ponderous to
rely on it for the purpose you want it. I think it would be slightly
safer to be explicit and use the -1 (minus one) option. For instance:

IFS="";
for img in `ls -1 *.jpg`; do
    ...
done

*However* in this case you don't need to use `ls` at all. Just do:

for img in *.jpg; do
    ...
done





More information about the plug mailing list