Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How to iterate over lines cross-platform
- X-seq: zsh-users 15002
- From: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: How to iterate over lines cross-platform
- Date: Sun, 11 Apr 2010 17:47:09 +0200
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <hpqcvj$avi$1@xxxxxxxxxxxxxxx> <100410130524.ZM17378@xxxxxxxxxxxxxxxxxxxxxx>
* 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