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

Re: Little problem while converting from bash (quoting/splitting?)



"krasnal" wrote:
> This is with 4.2.4 cygwin version of zsh and 2.05b.0(1)-release of bash.
> cleartool is windows program producing \r\n line terminated output.  Note
> that zsh has both \r and \n in f variable while bash has only \n.  This is
> a bit problematic for me because I'm eventually using these values for output
> and the \r chars screw it up.

Well, you could add \r to IFS, but unfortunately that will generate extra
blank lines, for example:

% (IFS=$' \t\n\000\r'; for f in $(print "foo\r"); do print $f | xxd; done)
0000000: 666f 6f0a                                foo.
0000000: 0a                                       .

Because you're selecting using a "case", it's possible these don't
affect you, however.

zsh makes it relatively straightforward to remove the trailing \r by
surrounding the command substitution with a parameter-style expansion:

% for f in ${$(print "foo\r")%%$'\r'}; do print $f | xxd; done
0000000: 666f 6f0a                                foo.

(That only works if \r is *not* in IFS.)

There's no mechanism for automatically turning \r\n into \n, however.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

**********************************************************************



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