Re: Question on $@ vs $@$@

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

 



Hello.

Unfortunately i have to add one thing to this thread..

Steffen Nurpmeso wrote in
 <20240814200534.Vh3Eu_Md@steffen%sdaoden.eu>:
 |Chet Ramey wrote in
 | <1bba673e-5ab9-4263-9d88-124854793b4b@xxxxxxxx>:
 ||On 8/13/24 8:45 PM, Steffen Nurpmeso wrote:
 ||> I include bug-bash even though i think bash is correct, but there
 ||> lots of people of expertise are listening, so, thus.
 ||> Sorry for cross-posting, nonetheless.
 ||> Given this snippet (twox() without argument it is)
 ||> 
 ||>    one() { echo "$# 1<$1>"; }
 ||>    two() { one "$@"; }
 ||>    twox() { one "$@$@"; }
 ||>    two
 ||>    two x
 ||>    twox
 ||>    twox x
 | ...
 ||When, as in this case, the result would be split if the double quotes
 ||weren't there, $@ within double quotes expands to nothing if there are
 ||no positional parameters, no matter how many times it appears.
 |
 |As was shown there is standard wording which makes this case
 |explicitly unspecified.  Thanks for pointing this out.  I should
 |have reread the standard first (that particular wording is hard to
 |grasp for me).
 ...

In fact Geoff Clare (who we all deserve thanks, together with Don
Cragun, for continued ISO C compiler support for the BSD socket
interface we all use in at least POSIX environments, it is
undefined anywhere else!, and more) sees this differently:

  The standard clearly requires "$@$@" to generate zero fields if
  there are no positional parameters. The quoted text "if the
  expansion is embedded within a word which contains one or more
  other parts that expand to a quoted null string, ..." does not
  apply because there are no other parts that expand to a quoted
  null string. (The second $@ is not a candidate for being such
  a part because "the expansion of '@' shall generate zero
  fields".)

  If this does not match existing behaviour in some shells, we
  could consider making it unspecified, but the first step should
  be to alert the maintainers of those shells to the issue and
  find out whether they are willing to change their shell to
  comply with the standard.

So please any shell maintainer listening here, please feel
alerted.

(P.S.: regarding

  > I'd still love to know what the script's intent is.

It will be a test.  My MUA does not yet apply word splitting for
unquoted variable expansions, and while going that road, there was
a pitfall.)

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux