Re: Parameter Expansion

Vin Shelton <[email protected]>
Newsgroups gmane.comp.shells.zsh.devel,gmane.comp.shells.zsh.user
Message-ID <CACeGjnXeO_Ry=sd=WyodsxkgTNJ6zh5_fZ2duPSj-LsmvUV3Ow@mail.gmail.com>
> Are you leaving the first element unmodified intentionally?
No. I had to add ${HOME}/ to the beginning of my print command. Is there a
way to automatically add it to every element of the array?

> 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.

Thanks for pointing that out.

On Tue, Jul 15, 2025 at 5:02 PM Lawrence Velázquez <[email protected]> wrote:

> 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
>


-- 
Whoa, I'm just surprised at how accurate that description of me really is:
some old cowboy guy that used to shoot movies at Spahn Ranch
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.