zsh-users
 help / color / mirror / code / Atom feed
* join a string with a parameter value if it's not empy
@ 2023-02-03 23:43 sergio
  2023-02-04  0:20 ` Eric Nielsen
  2023-02-04  0:23 ` Eric Nielsen
  0 siblings, 2 replies; 7+ messages in thread
From: sergio @ 2023-02-03 23:43 UTC (permalink / raw)
  To: zsh-users

Hello.

I'd like to prepend a string with a parameter's value + separator.

p='value' -> result: 'value_string'
p=''      -> result: 'string'

I found two solutions:

${p:+${p}_}string
${(j:_:)${=${:-$p string}}}

but both looks too complicated for my feel.
Is there something simpler and prettier?

-- 
sergio.


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-02-04  8:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-03 23:43 join a string with a parameter value if it's not empy sergio
2023-02-04  0:20 ` Eric Nielsen
2023-02-04  2:01   ` sergio
2023-02-04  3:30     ` Eric Nielsen
2023-02-04  4:03     ` Bart Schaefer
2023-02-04  8:39       ` Stephane Chazelas
2023-02-04  0:23 ` Eric Nielsen

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).