For loops, Spaces in values
shaun etherton
shaun at internode.on.net
Tue Nov 28 00:37:58 CST 2006
Andrew Reid wrote:
> Suppose I have a program that returns a list of files, but those files
> contain spaces:
>
> /tmp/My File One.txt
> /tmp/My File Two.txt
>
> If I try and do a for loop over it, like:
>
> for i in `listdirs` do
> echo $i
> done
>
> (where list dirs is the program that generates the aforementioned
> output), I get the following output from the loop:
>
> My
> File
> One.txt
> My
> File
> Two.txt
>
> So, how do I get the for loop to iterate over my list, but not delimit
> that list by spaces?
>
> Cheers,
>
> - andrew
>
I think you need to change the delimeter from a space to a newline
character. I can't remember the name of the variable though. :)
IFS I think..
cheers,
- shaun
More information about the linuxsa
mailing list