Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
How to iterate over lines cross-platform
- X-seq: zsh-users 15000
- From: Thorsten Kampe <thorsten@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: How to iterate over lines cross-platform
- Date: Sat, 10 Apr 2010 19:36:37 +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
Hi,
I wrote a Zsh shell script which iterates over the output of an external
tool ("slptool"). Each line of output is an item so I did this:
###
IFS=$'\n'
for scope in $(slptool findscopes); do
for srvtype in $(slptool -s "$scope" findsrvtypes); do
[inner loop]
done
done
###
This works fine on Linux. Unfortunately the script does not works under
Cygwin. It never enters the "for srvtype" loop (or it doesn't produce
output). The reason is that the slptool on Windows is a native Win32
application that outputs lines with "\r\n" endings (and not "\n").
So I simply set "IFS=$'\r\n'" and now the output is correct - but the
scipt goes through an additional iteration for each loop so output is
duplicated or results in an error at the end. I suspect that the shell
does not split on "\r\n" but either on "\r" or "\n".
How can I iterate over lines of output when I don't know in advance
whether the line endings will be DOS or Unix?!
Thorsten
Messages sorted by:
Reverse Date,
Date,
Thread,
Author