[ale] Keep space separated values sane in a bash "for" loop?

Jim Popovitch jimpop at yahoo.com
Fri Apr 6 01:53:41 EDT 2007


On Fri, 2007-04-06 at 01:38 -0400, Christopher Bergeron wrote:
> Drat!  Something isn't working.  Perhaps its the fact that I'm beyond my 
> bedtime, or perhaps this code just doesn't work:
> 
> #!/bin/bash
> export oldifs=$IFS
> export IFS=" $'\n' "
> for i in `\ls`; do echo $i; done
> export IFS=$oldifs
>
> 
> The code works, but it interprets every "n" literally and substitutes it 
> with a newline.  I'm missing something obvious here, but it's late, and 
> I'm tired.  Perhaps someone can spot it.  The $IFS var, uses a $ and 
> regexps within single quotes - so what am I missing?
> 
> Kind regards and TIAa,
> CB

Hi Chris,

Perhaps I missed something from earlier in this thread, but why won't
this work for you:

#!/bin/bash
export oldifs=$IFS
export IFS="$"
for i in `ls`; do echo $i; done
export IFS=$oldifs

-Jim P.






More information about the Ale mailing list