Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How to iterate over lines cross-platform



* Bart Schaefer (Sat, 10 Apr 2010 13:05:24 -0700)
> On Apr 10,  7:36pm, Thorsten Kampe wrote:
> } How can I iterate over lines of output when I don't know in advance 
> } whether the line endings will be DOS or Unix?!
> 
> You might have better luck if you do not change IFS from the default,
> and use this:
> 
> slptool findscopes |
> while read scope; do
>     slptool -s "$scope" findsrvtypes |
>     while read srvtype; do
>         [inner loop]
>     done
> done

Actually modifying IFS is not necessary (shame on me for the confusion).
 
> It should be the case that "read" does the right thing with line ends.
> 
> } The reason is that the slptool on Windows is a native Win32 
> } application that outputs lines with "\r\n" endings (and not "\n").
> 
> I believe this means that "$scope" has a trailing "\r" and therefore
> slptool -s "$scope" doesn't find a matching scope.  If it turns out
> that "read" also mishandles things, use ${scope%$'\r'} to trim.

I didn't try "read" but "%$'\r'" does the "trick".

Thanks, Thorsten



Messages sorted by: Reverse Date, Date, Thread, Author