Let's assume I have an array
> words=(foo bar baz)
Now I can join the elements
> echo ${(j., .)words}
foo, bar, baz
And I can append a string to the elements:
> echo ${^words}yeah
fooyeah baryeah bazyeah
With the following, I can append and join the elements:
> wordsyeah=(${^words}yeah)
> echo ${(j., .)wordsyeah}
fooyeah, baryeah, bazyeah
Is it possible to do print "fooyeah, baryeah, bazyeah" in a single expression, i.e. without using additional variables?
Bonus: Can I print that without using any variables at all?
As far as I can tell, this boils down to running parameter expansion on strings, but I wasn't able to find out how (or if) that is possible.
echo ${(j:, :):-${^${=:-foo bar baz}}yeah}
, which is actually harder to type and 12 characters longer thanecho fooyeah, baryeah, bazyeah
. So it mainly makes sense if variables are involved, for exampleecho ${(j:, :):-${^${words}}yeah}
(withwords
being an array).