From: Clint Hepner <clint.hepner@gmail.com>
To: Bernd Steinhauser <linux@bernd-steinhauser.de>
Cc: zsh-users@zsh.org
Subject: Re: Mapping quoted parameter in function
Date: Thu, 10 Nov 2016 07:29:55 -0500 [thread overview]
Message-ID: <22F03E0F-5C12-41EC-BD57-72139A3534D7@gmail.com> (raw)
In-Reply-To: <0a521f25-d548-d3b1-fb2e-7559f7995b7d@bernd-steinhauser.de>
> On 2016 Nov 10 , at 1:20 a, Bernd Steinhauser <linux@bernd-steinhauser.de> wrote:
>
> Hi,
>
> I'm using a program that expects a parameter (actually multiple parameters) in the form
> program "foo='bar'"
>
> Because the cmdline for that program gets quite long, I wrote a function to call it and change parameters easily,it looks roughly like this:
> progfunc() {
> CORES=12
> program -n ${CORES} "foo='bar'" foo2="1 $3"
> }
>
> What I would want to do is to ensure that if I call
> `progfunc x`
>
> this would translate into "foo='x'", without touching the rest of the call.
> Is that somehow possible?
> iirc, variables won't work, because of the quoting style?
>
> Best Regards,
> Bernd
Just replace bar with a parameter default expansion.
progfunc () {
CORES=12
program -n $CORES "foo='${1:-bar}' foo2="1 $3"
}
progfunc # foo='bar'
progfunc "hi there" # foo='hi there'
If you don’t pass a first argument, bar is used. Otherwise, the value of the argument is.
The single quotes here don’t actually quote anything; they are literal characters included in the *double*-quoted string.
Clint
next prev parent reply other threads:[~2016-11-13 4:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-10 6:20 Bernd Steinhauser
2016-11-10 12:29 ` Clint Hepner [this message]
2016-11-10 16:48 ` Bernd Steinhauser
[not found] <0a521f25-d548-d3b1-fb2e-7559f7995b7d__49592.623851686$1478759489$gmane$org@bernd-steinhauser.de>
2016-11-10 16:10 ` Daniel Shahaf
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=22F03E0F-5C12-41EC-BD57-72139A3534D7@gmail.com \
--to=clint.hepner@gmail.com \
--cc=linux@bernd-steinhauser.de \
--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).