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

Re: Strip a Carriage-Return from a string/variable



zzapper wrote:
> Hi
> print ${somevar//[^[:alnum:]]/_}   # replace all non-alphanumerics with _
> 
> But how to delete just a trailing or not carriage return?

% foo=$'bar\r'
% print $foo | xxd
0000000: 6261 720d 0a                             bar..
% print ${foo%%$'\r'} | xxd
0000000: 6261 720a                                bar.

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


'member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom'



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