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

Re: string overwrites string when echoed



On Sun, 10 Sep 2017 20:23:08 +0200
Emanuel Berg <moasen@xxxxxxxx> wrote:
> Feel free to elaborate on ${reply%%$'\r'}.
> What does it do? Remove the last char of the
> string if it matches the char given?

%% is a standard pattern match operator (works in most shells) that
removes the longest possible match of the following pattern.  % is
similar but removes the shortest possible match: I used %% because they
do the same thing in this case (it's a single fixed character) and I
happen to know the longest match is generally more efficient to
evaluate.  This is documented in the PARAMETER EXPANSION section of the
zshexpn manual.

$'...' is an increasingly common form of quoting that allows escape
sequences like the print builtin, so $'\r' exands to a carriage return.
This is documented in the section QUOTING in the zshmisc manual page
(except it doesn't say much more than what I did before you have to go
away and read the entry for the print builtin).

pws



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