From: Bernd Steinhauser <linux@bernd-steinhauser.de>
Cc: zsh-users@zsh.org
Subject: Re: Mapping quoted parameter in function
Date: Thu, 10 Nov 2016 17:48:22 +0100 [thread overview]
Message-ID: <b303227f-ff30-82b4-2ebc-0fd447a0f48e@bernd-steinhauser.de> (raw)
In-Reply-To: <22F03E0F-5C12-41EC-BD57-72139A3534D7@gmail.com>
On 10/11/16 13:29, Clint Hepner wrote:
>
>> 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.
Thanks, so my misunderstanding actually led me to not even try this.
Feels a bit embarrassing. ;)
next prev parent reply other threads:[~2016-11-10 16:48 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
2016-11-10 16:48 ` Bernd Steinhauser [this message]
[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=b303227f-ff30-82b4-2ebc-0fd447a0f48e@bernd-steinhauser.de \
--to=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).