[plug] word splitting

Luke Dudney ldlist at westnet.com.au
Wed Nov 17 16:10:05 WST 2004


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:
>
>for img in `ls *.jpg`
>do
>    echo $img
>done
>
>it works fine as long as there are no spaces in the filename - if there's a 
>space, $img is broken down into words (eg, if the filename is "file name.jpg", 
>$img on the first iteration is "file" & on the second iteration is "name.jpg").
>
>Gavan Blunt.
>  
>

The "word splitting" you're describing is determined by bash's IFS 
variable. By default, it is any whitespace (space, newline, tab etc) but 
can be changed to something arbitrary. man bash should have more, but as 
a quick fix to your immediate problem you could do the following:

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

Cheers
Luke





More information about the plug mailing list