Wanted: quoted param expansion that expands to nothing if no params
From:
L A Walsh
Subject:
Wanted: quoted param expansion that expands to nothing if no params
Date:
Tue, 23 Mar 2021 20:24:03 -0700
User-agent:
Thunderbird 2.0.0.24 (Windows/20100228)
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:
<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?