Date:        Sun, 25 Aug 2024 04:08:58 +0200
    From:        Steffen Nurpmeso <stef...@sdaoden.eu>
    Message-ID:  <20240825020858.nrX4pFTm@steffen%sdaoden.eu>

  | (The only thinkable answer is that the step that my MUA does,
  | namely resolving $* as a single string first, does not happen,
  | right?

That's correct.   When (first) expanding $* the value of IFS
is irrelevant, except for expansions where field splitting won't
later be performed (ie: never would be performed, regardless of
the value of IFS) - eg: VAR=$* or more commonly "$*".

After the fields have been expanded, then the results of those
expansions are subject to field splitting, for which IFS is
relevant.

That is, given

        set -- a b c

$* produces 3 fields, "a" "b" and "c" (not quoted of course)
which are then subject (individually) to field splitting.
If we had IFS=b then the middle field would turn into nothing,
leaving just "a" and "c".

  | I really have to carefully read the standard on Monday.)

For this see XCU 2.5.2, the descriptions of the expansions of
the special parameters, $@ and $* are the first two listed.
When unquoted, they're identical:

        Expands to the positional parameters, starting from one, initially
        producing one field for each positional parameter that is set. When
        the expansion occurs in a context where field splitting will be
        performed, any empty fields may be discarded and each of the non-empty
        fields shall be further split as described in Section 2.6.5.

After that, when the expansion is in a context where field splitting
won't be performed, then $* and $@ are processed differently - with
$@ only being defined in a few cases in this circumstance.   2.6.5
says how IFS is used to (potentially) break those fields up info smaller
fields.

For $* in a non-field-splitting context, it goes on to say:

        When the expansion occurs in a context where field splitting will
        not be performed, the initial fields shall be joined to form a
        single field with the value of each parameter separated by the first
        character of the IFS variable if IFS contains at least one character,
        or separated by a <space> if IFS is unset, or with no separation if
        IFS is set to a null string.

If that happens, since we know we're in a context where field splitting
doesn't happen, we're done (just quote removal to follow - as not doing
field splitting usually also means not doing pathname expansion - though
some shells will do pathname expansion on the word after a redirect operator,
sometimes.)

kre



Reply via email to