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: Dale R. Worley
Subject: Re: Wanted: quoted param expansion that expands to nothing if no params
Date: Wed, 24 Mar 2021 22:04:14 -0400

L A Walsh <bash@tlinx.org> writes:
> 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)

Fiddling a bit, I found this is a nice way to show how "$@" (or any
other construction) affects the parameters given a to command.

    $ function show { ( set -x ; echo "$@" >/dev/null ) }
    $ show a
    + echo a
    $ show a b
    + echo a b
    $ show ''
    + echo ''
    $ show a ''
    + echo a ''
    $ show
    + echo
    $ 

What makes it particularly effective is that "set -x" shows the sequence
of arguments unambiguously.  (Hmmm, I could have used ":" instead of
"echo".)

And the manual page does make this clear if you read the entire
description:

              When there are no positional parameters, "$@" and $@  expand  to
              nothing (i.e., they are removed).

Dale



reply via email to

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