bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Wanted: quoted param expansion that expands to nothing if no params


From: Eli Schwartz
Subject: Re: Wanted: quoted param expansion that expands to nothing if no params
Date: Tue, 23 Mar 2021 23:43:46 -0400

On 3/23/21 11:24 PM, L A Walsh wrote:
> Too often I end up having to write something like
> if (($#)); then <func|exec> "$@"
> else <func|exec>      #<func|exec> = function or executable call
> fi
> 
> It would be nice to have a expansion that preserves arg boundaries
> but that expands to nothing when there are 0 parameters
> (because whatever gets called still sees "" as a parameter)
> 
> So, example, something like:
> 
> $~ == "$@" #for 1 or more params
> $~ ==  no param when 0 param, # so for the above if/else/endif
> one could just use 1 line:

It's not clear to me, how you expect this to differ from the existing
behavior of "$@" or "${arr[@]}" which already expands to <nothing>
rather than an actual "" parameter.

>   <func|exec> $~
> 
> My examples used ~, as I didn't think it was used anywhere.
> 
> I can't control how called programs will handle / deal with a
> present, but empty parameter, which is why I thought something that
> expands to nothing in the empty case would seem ideal.
> 
> Anyone else have a trivial solution for this problem?

Does "be mindblown when it worked as is to begin with" count?

-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]