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

Re: using \r in a while statement



On Sep 23,  1:41am, Alan Third wrote:
} Subject: using \r in a while statement
}
} I'm using a while loop to read in the article a line at a time.
} The article is ended by a line which only has .\r\n on it, so
} [...] I've ended up with:
} while [[ $LINE != `echo ".\r"` ]]; do
}     readline
}     printline
} done

If you have zsh 3.1.4 or later, use $'\r' as in [[ $LINE != $'.\r' ]].
The meaning of $'STRING' is that STRING is expanded as if with the
print builtin.

If you have an older zsh, you can still do it, with a considerably less
comprehensible syntax: [[ $LINE != ${(pr(2)(\r)):-.} ]]

Which means, working from the :- outward: expand nothing, and if you
get back nothing (which you must), then replace that with a dot, and
then pad that on the right with \r so the result is 2 characters wide,
interpreting the \r as if it were output by the print builtin.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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