Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: :s modifier right-hand-side value behaves strangely with a variable
- X-seq: zsh-workers 55110
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Jonathan Poelen <jonathan.poelen@xxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: :s modifier right-hand-side value behaves strangely with a variable
- Date: Sun, 23 Aug 2026 13:22:10 -0700
- Arc-authentication-results: i=1; mx.google.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=c4NkmIARdEDGdTSXVufAlLXMEln26cUDl7iQOgO/JRU=; fh=lj+Yo+0B75PO9444blLRoPQegX6Sqq+NNuidZoTqPG0=; b=haz5Wef1d3+NM/xUVsEcWjv+fcrv1pbsNmyGRt4KgK45aZpoepHgHmKG8iRdFitrtl pxb0wb9cfoLSWOxtGC7dEf1azUhsOnmo/GKeWBNcWpDPD6nUWr/239r8iDcigyla/BpB JEWUlhgPemh9oDk58GgS3tLO4P7An8EXAlUkAP/jO3PdlOuoNt4NUcMPHpH3vsJAsYe1 XTgDhmBOm3wb1nxi61RWoRG7z1gqHlSXVvZ5x3Ja+ucQqtfk3js7nSlLO5RRsnMWB5su qCSmwI8auvdq3xUDhpj7182KKwo50uUnpbHZh8Ut3Nj/v8pNXuRitYGn70rDfooPFnc4 Ej3Q==; darn=zsh.org
- Arc-seal: i=1; a=rsa-sha256; t=1787516542; cv=none; d=google.com; s=arc-20260327; b=aq8MzWYqInz/xgEaTX0DDkpJhkHIAQpIw1iMxS4ocKG4evj1qhqnhLe/Xe6/qYy905 EOPSdWiV9CrpaqtJ4pJFCH+hFHGcGAXeQlpidiXaqQXkMtKL0+FT+/2HlGDz7eQmvPX/ 4GR9wsLLcFCelnSQC/7SVBsLKL3hfFgVbb6TX9lmKUXPeOPsrePAY+NUEP6NhaV46mkG npAyIfNRg2LOVnlVx+Fs0ySFGWUBWFjfy8DBATe917Lmm9xT5SqyWAo93pbilmeVFYXQ ueP/JiKX9Rr/51P6StPp/cRd0fDtWTHS4tYXiKDAlwu8bsxy22TQojdYmoQpXJ8NOhC8 QMFw==
- Archived-at: <https://zsh.org/workers/55110>
- In-reply-to: <CAAqh98M5xi5AoK0aFS4gmY6wCCedn=KhLPEGsyRY69YgmgDGww@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAAqh98M5xi5AoK0aFS4gmY6wCCedn=KhLPEGsyRY69YgmgDGww@mail.gmail.com>
On Sun, Aug 23, 2026 at 7:29 AM Jonathan Poelen
<jonathan.poelen@xxxxxxxxx> wrote:
>
> When a variable is used in the replacement part of the :s/l/r/ modifier,
> the result depends on various obscure conditions, which leads to a truncated
> replacement and a found string that is longer than the search string.
You're making an incorrect assumption about evaluation order.
str='abc,abc'
echo $str:s/b/$rep
results in 'a$repc,abc' which then expands as "a${repc},abc" because
without braces the $varname parse consumes everything that looks like
part of an identifier, stopping when it reaches the comma.
If you put braces around ${rep} you get "a${rep}c,abc" which is the
result you expected.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author