Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Mapping quoted parameter in function
- X-seq: zsh-users 22119
- From: Clint Hepner <clint.hepner@xxxxxxxxx>
- To: Bernd Steinhauser <linux@xxxxxxxxxxxxxxxxxxxx>
- Subject: Re: Mapping quoted parameter in function
- Date: Thu, 10 Nov 2016 07:29:55 -0500
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=HGkZ8sv7POzQ+03P5lxB8uJc+ZJqVwVIOO5P7WOXyes=; b=Ikyms840zYpmwFYhGwEDSfyS7sqWNoDZScVXTFGQfcgEsP7YQW6k1eOJjys/amb3Mh 8Gp4Mg4sQvHDT+1I0Y/iRO0AACZWDU1GtBWnbD6eYTrlJhPvMydCFWzS9f76D6QGCtB/ Uk4yJu8c4xTsrz7QRrBd6GxgOhwgwO9oOViG/mEsZSDVvPcwCD3dF26Zd+c9vltiziQN j2XCIUJj1UFDd0DZbeLsAiGk7C1XFS7Ouf4lo6u3h8h0hDtTghXNFG/tJ3CF/uWGRKvg z9ceiV+IqyjSB5L4kw2LMyu7+zbWYSO4GrOWYLp+mpXcvsfz1OdMq93cHu6gYr6h9umO KlAw==
- In-reply-to: <0a521f25-d548-d3b1-fb2e-7559f7995b7d@bernd-steinhauser.de>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <0a521f25-d548-d3b1-fb2e-7559f7995b7d@bernd-steinhauser.de>
> On 2016 Nov 10 , at 1:20 a, Bernd Steinhauser <linux@xxxxxxxxxxxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author