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

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



On Tue, Aug 25, 2009 at 5:52 PM, zzapper wrote:
> Peter Stephenson wrote:
>
>> zzapper wrote:
>
>> % foo=$'bar\r'
>> % print $foo | xxd
>> 0000000: 6261 720d 0a               bar..
>> % print ${foo%%$'\r'} | xxd
>> 0000000: 6261 720a                Âbar.
>>
> Thanks Peter
> And anywhere in the variable/any number of times?

Then you'd go with what Frank Terbeck suggested.

% foo=$'bar\r\rbaz'
% print $foo | xxd
0000000: 6261 720d 0d62 617a 0a                   bar..baz.
% print ${foo//$'\r'/_} | xxd
0000000: 6261 725f 5f62 617a 0a                   bar__baz.

~Matt



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