bug-bash
[Top][All Lists]
Advanced

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

Re: $@ in function gives error


From: alex xmb sw ratchev
Subject: Re: $@ in function gives error
Date: Sat, 17 Aug 2024 13:04:54 +0200

On Sat, Aug 17, 2024, 12:42 Freek de Kruijf <f.de.kruijf@beelaertsict.nl>
wrote:

> Op zaterdag 17 augustus 2024 00:29:23 CEST schreef u:
> > On Fri, Aug 16, 2024, at 12:59 PM, freek--- via Bug reports for the GNU
> >
> 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.
> >
> >       $ set -x a b c d
> >       $ test -n "$@"
> >       + test -n a b c d
> >       bash: test: too many arguments
> >
> Apparently I have a problem with the concept of $@, I see it as list of
> zero
> or more non-whitespaced elements, and quotes around it makes it into a
> single
> element. Like a parameter p with a content of zero or more non-whitespaced
> elements, where the quotes make in into a single element.
>

it makes every of $@ , eg $1 $2 , into its own arg , if its used inside
double quotes "$@"
$* makes it such a one-string , separated by first char of IFS var

Thanks for teaching me this concept. It must have some meaning in more
> complicated situations.
>
> A test -n "$1" has also the effect I was looking for as the suggested one
> $# -ne 0 .
>
> --
> fr.gr.
>
> Freek de Kruijf
>
>
>
>


reply via email to

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