[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question on $IFS related differences (Was: Question on $@ vs $@$@)
From: |
Steffen Nurpmeso |
Subject: |
Re: Question on $IFS related differences (Was: Question on $@ vs $@$@) |
Date: |
Wed, 18 Sep 2024 23:37:59 +0200 |
User-agent: |
s-nail v14.9.25-608-ge479530e8d |
Chet Ramey wrote in
<b72edbc9-d336-4391-98a9-37c670afa435@case.edu>:
|On 9/18/24 1:05 AM, Oğuz wrote:
|> On Wed, Sep 18, 2024 at 4:19 AM Steffen Nurpmeso <steffen@sdaoden.eu> \
|> 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.htm\
|l#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.
Thank you for this analysis.
(Here it is just a shell expander, ie, it acts like a format
string expander, and these steps you include, namely "quote
removal" etc, are nothing i can or want to mimic.)
|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.
--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)
- Question on $IFS related differences (Was: Question on $@ vs $@$@), Steffen Nurpmeso, 2024/09/17
- Re: Question on $IFS related differences (Was: Question on $@ vs $@$@), Oğuz, 2024/09/18
- Re: Question on $IFS related differences (Was: Question on $@ vs $@$@), Greg Wooledge, 2024/09/18
- Re: Question on $IFS related differences (Was: Question on $@ vs $@$@), Chet Ramey, 2024/09/18
- Re: Question on $IFS related differences (Was: Question on $@ vs $@$@),
Steffen Nurpmeso <=
- Re: Question on $IFS related differences (Was: Question on $@ vs $@$@), Robert Elz, 2024/09/18
- Re: Question on $IFS related differences (Was: Question on $@ vs $@$@), Steffen Nurpmeso, 2024/09/18
- Re: Question on $IFS related differences (Was: Question on $@ vs $@$@), Robert Elz, 2024/09/18