[Top][All Lists]

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

Re: Unexpected word splitting on $* when IFS is unset

From: Robert Elz
Subject: Re: Unexpected word splitting on $* when IFS is unset
Date: Sat, 24 Jun 2017 21:10:34 +0700

    Date:        Sat, 24 Jun 2017 07:59:25 -0500
    From:        Eduardo =?utf-8?Q?A=2E_Bustamante_L=C3=B3pez?= <address@hidden>
    Message-ID:  <address@hidden>

  | I think we can all agree that the rules (and bugs) around
  | the expansion of $* are too complex.

The bugs in various implementations cause problems, yes, dealing with
someone else's mistakes (and especially doing it in a way that things
still work when the bugs get fixed) can be difficult.

But the rules, no, the rules for $* are actually trivial.

Unquoted, $* (or $@ which is identical) is exactly the same
as the sequence

        $1 $2 $3 ...

would be, if we knew in advance how many of those we should write
(which can be 0 of them of course.)

It is exactly that simple (ignoring implementation bugs.)

The only slight complication is when we have a$*b (for any a and b).
But that's just as simple really, "a" gets attached to the first of the
$n's produced (usually $1 unless $# is 0), and "b" gets attached to the
last.   So if $# is 3 we get
        a$1 $2 $3b
(with the obvious extension to bigger $# values).  For $# = 2 it
is just a$1 $2b , for $# = 1, a$1b and for $# = 0 we get just ab

No-one has any problem understanding what $1 means or what a
sequence of args means, and $* just combines those two.

When quoted, $@ (ie: "$@") is just as simple, except each $n generated
is quoted "$1" "$2" "$3" (and the combining rule for adjacent text is
the same as above.)   And just as above $# can be 0, and nothing (assuming
no attached text) is generated.

All that is left is "$*" which just produces "$1x$2x$3x" for as many
args that exist, where 'x' is the first char of IFS (and may be nothing
at all).   In this one the "" string is always generated, even when $# is 0,
it is just empty then.


reply via email to

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