From: sergio <sergio@outerface.net>
To: zsh-users@zsh.org
Subject: join a string with a parameter value if it's not empy
Date: Sat, 4 Feb 2023 03:43:26 +0400 [thread overview]
Message-ID: <81c93630-34fd-7e2d-39bb-e5f8cc5b344e@outerface.net> (raw)
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.
next reply other threads:[~2023-02-03 23:44 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-03 23:43 sergio [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=81c93630-34fd-7e2d-39bb-e5f8cc5b344e@outerface.net \
--to=sergio@outerface.net \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).