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