From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12670 invoked by alias); 10 Nov 2016 16:48:39 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22111 Received: (qmail 13560 invoked from network); 10 Nov 2016 16:48:39 -0000 X-Qmail-Scanner-Diagnostics: from outbound2.flatbooster.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(84.200.223.10):SA:0(-1.7/5.0):. Processed in 0.503799 secs); 10 Nov 2016 16:48:39 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MISSING_HEADERS,RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: SRS0=qAyv=W3=bernd-steinhauser.de=linux@flatbooster.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at flatbooster.com does not designate permitted sender hosts) X-Virus-Scanned: Debian amavisd-new at outbound2.flatbooster.com Subject: Re: Mapping quoted parameter in function References: <0a521f25-d548-d3b1-fb2e-7559f7995b7d@bernd-steinhauser.de> <22F03E0F-5C12-41EC-BD57-72139A3534D7@gmail.com> Cc: zsh-users@zsh.org From: Bernd Steinhauser Message-ID: Date: Thu, 10 Nov 2016 17:48:22 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <22F03E0F-5C12-41EC-BD57-72139A3534D7@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 10/11/16 13:29, Clint Hepner wrote: > >> On 2016 Nov 10 , at 1:20 a, Bernd Steinhauser 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. ;)