Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Mapping quoted parameter in function



Bernd Steinhauser wrote on Thu, Nov 10, 2016 at 07:20:17 +0100:
> 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?

If you want to get «x» as your $1 argument and have the callee see
«foo='x'» as its argument, you can do this:

    progfunc() { program "foo='$1'" }

Or this:

    progfunc() { program "foo=${(q)1}" }

If that doesn't answer your question, then please clarify it.

> iirc, variables won't work, because of the quoting style?

«"foo'$bar"» does interpolate $bar as a variable, despite the single
quote in there, because the ' is literal (part of the string data).
«"foo"'$bar'» doesn't, because the ' is syntactical.

Cheers,

Daniel


> Best Regards,
> Bernd
> 



Messages sorted by: Reverse Date, Date, Thread, Author