bug-bash
[Top][All Lists]
Advanced

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

Re: Word splitting for $@ in variable assignment


From: Robert Elz
Subject: Re: Word splitting for $@ in variable assignment
Date: Sat, 26 Jun 2021 01:05:48 +0700

    Date:        Fri, 25 Jun 2021 12:11:33 -0400
    From:        Greg Wooledge <greg@wooledge.org>
    Message-ID:  <YNYANaI3hq5tfxDW@wooledge.org>

  | That matches the behavior that I saw (and pasted on this mailing list the
  | other day).  (Which by the way is *not* the same as "$*" unless IFS happens
  | to be unset or to begin with a space.)

Hmm, never saw that difference before, I wonder why - mksh and ksh93 do
it that way as well.   Other shells (except bosh, which is simply broken
in this area, but might be intended to be the same as bash) - that is
all the ash descendents (including dash), plus yash, and zsh, all treat $@
as being just the same as $* in contexts where only one word is to be
produced.   After all, why not, reuse the code...

POSIX just says (or will say if it doesn't already) it is unspecified,
so either is OK (and applications simply should not do that).

Either way the quotes in x="$@" (or x="$*") do nothing at all, as is true
of any other var assign, except where the value to be assigned (as written
in the script or command line) contains a sh magic character (operator,
quoting char, white space).

  | If Chet feels that a change is needed here, I would remove the "with
  | the exception of" clause entirely.  Just say "Word splitting is not
  | performed."

My suspicion (I'm guessing) is that exception is to cover

        x=("$@")

where the "$@" is expanded to multiple words (but still this isn't word
splitting).   (Here "value" in the man page is ("$@") (including the
parentheses and quotes) in the example).

kre




reply via email to

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