On Fri, Aug 16, 2024, at 6:29 PM, Lawrence Velázquez wrote:
> There is no problem with "$@" or functions here.  The "problem" is
> that "$@" expands to multiple fields when there are two or more
> positional parameters, so (as the error message says) you end up
> running test(1) with too many arguments.  This is a usage error.
>
> [...]
>
> What are you trying to test for, anyway?  Whether there are any
> positional parameters?  The latter test (which you claim "works
> OK") does succeed when there are nonempty positional parameters,
> but it also succeeds when there are multiple parameters that are
> all empty, and it fails when there is a single empty parameter.

Also note that when there are no positional parameters, "$@" expands
to *zero* fields, breaking the first test in a different way.

        $ set -x --
        $ test -n "$@"; : "$?"
        + test -n
        + : 0

It succeeds because "-n" is the only argument, and test(1) always
succeeds when invoked with a single nonempty argument.

-- 
vq

Reply via email to