On 9/18/24 1:05 AM, Oğuz wrote:
On Wed, Sep 18, 2024 at 4:19 AM Steffen Nurpmeso <steffen@xxxxxxxxxx> wrote:
It boils down to this:
f(){ echo $#;}; set "" "" ""; IFS=x; f $*
bash, NetBSD and FreeBSD sh, and ksh88 all agree and print 2. pdksh
prints 3 but mksh and oksh print 1. dash, ksh93, yash, and zsh print
0.
It's an implementation difference.
The shells that print `0' treat the `may' as `shall' in this sentence from
https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_05_02
"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 2.6.5 Field Splitting."
So they immediately expand the $* to nothing.
The shells that print `2' don't immediately discard the empty fields and
separate them with the first character of IFS. After quote removal and
removing the empty fields, since the individual words in $* are subject
to additional expansion, you're left with `xx'. When you split that,
you get two empty fields.
I'm not sure what's going on with the shells that print `1' unless they
somehow don't use the first character of IFS to separate the arguments
and let multiple sequential delimiters terminate the first field.
I assume that pdksh just expands each positional parameter to a quoted
empty string and passes them all to f.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@xxxxxxxx http://tiswww.cwru.edu/~chet/