bug-bash
[Top][All Lists]
Advanced

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

Re: Question on $@ vs $@$@


From: Steffen Nurpmeso
Subject: Re: Question on $@ vs $@$@
Date: Tue, 27 Aug 2024 02:11:50 +0200
User-agent: s-nail v14.9.25-599-g5c75a327b2

Dear Robert, all.

Robert Elz wrote in
 <39.1724620450@jacaranda.noi.kre.to>:
 |    Date:        Sun, 25 Aug 2024 04:08:58 +0200
 |    From:        Steffen Nurpmeso <steffen@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.)

I will not get to this today, it is 2 o'clock in the morning and
i am happy shall i lay at 6.30 o'clock.
Thanks for your response, i will act accordingly.
Yes, here we "exploded" $* and $@ yet only if in double quotes,
otherwise they are looked up as normal variables (then subject to
the new word splitting).

Thank you very much for your answer.

 |kre
 --End of <39.1724620450@jacaranda.noi.kre.to>

--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)



reply via email to

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