Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Parameter Expansion
- X-seq: zsh-users 30315
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: "Vin Shelton" <ethersoft@xxxxxxxxx>
- Cc: zsh-users@xxxxxxx
- Subject: Re: Parameter Expansion
- Date: Tue, 15 Jul 2025 17:01:16 -0400
- Archived-at: <https://zsh.org/users/30315>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <CACeGjnVxbUeD7Ffh9mXH__DrfEvMU_sB=n3E9TY1WX6RtXp9Dw@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <CACeGjnWw4=9Hm9k0iXSoLDRYCfVxEz=uYrQ6MyBouRbFBbf7yw@mail.gmail.com> <44d1a0ff-b701-459c-aeb4-6b71e7c6cd62@gmx.com> <CACeGjnULdr+zyC=rmp8JbV-ouPgfJMGKSfQk1nYS=OrJ+xPQPA@mail.gmail.com> <a7778c85-7b00-4e13-85f8-926c8dba99aa@gmx.com> <ec4634ba-3370-4c6d-a712-15868928fbbf@gmx.com> <CACeGjnVxbUeD7Ffh9mXH__DrfEvMU_sB=n3E9TY1WX6RtXp9Dw@mail.gmail.com>
On Tue, Jul 15, 2025, at 1:07 PM, Vin Shelton wrote:
> Another issue arises with joining:
>
> home_files=(
> .local/share/baloo/index
> sshfs
> )
> print ${(j:\n${HOME}/:)home_files}
>
> This yields:
>
> .local/share/baloo/index
> ${HOME}/sshfs
Are you leaving the first element unmodified intentionally?
Note that '\n' has no special meaning to the "j" flag if you don't
use "p" also. It only becomes a LF character because your "print"
command is interpreting it.
> but I was expecting the ${HOME} to be interpreted. How do I do that?
If you prepend the "p" flag, then arguments to "j", "s", etc. of
the form "$var" are replaced with the contents of "var". So build
your glue string in a separate variable and use it like this:
% files=(foo bar baz)
% sep=$'\n'$HOME/
% printf '<%s>\n' ${(pj:$sep:)files}
<foo
/home/me/bar
/home/me/baz>
The form is exactly "$var"; substitution doesn't happen if you
include extra characters or use "${var}". This is not general
parameter expansion.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author