Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Discrepancy in IFS handling (zsh is POSIX compliant)



Hi,

indeed an original bourne shell, and ksh88 and ksh94 behave exactly like bash
On the other hand, tcsh and the ultra modern fish behave like zsh. 

Thus, I don't see the need for changing zsh. Let it as it is. It's in proud companionship. 

Cheers Tom

--- Ursprüngliche Nachricht ---
Von: Felipe Contreras <felipe.contreras@xxxxxxxxx>
Datum: 30.03.2023 13:11:46
An: Zsh Users <zsh-users@xxxxxxx>
Betreff: Discrepancy in IFS handling (zsh is POSIX compliant)

Hi,

I was going to report a bug about a discrepancy in the handling of
IFS, until I read what the POSIX standard says about it [1].

The example is this:

    IFS=,
    str='foo,bar,,roo,'
    printf '"%s"\n' $str

In bash there's four fields, the last comma is ignored, in zsh there's
five fields. In my system dash and ksh also output four fields, like
bash.

However, this is what POSIX says:

    3.b. Each occurrence in the input of an IFS character that is not
IFS white space, along with any adjacent IFS white space, shall
delimit a field, as described previously.

We ignore all the white space stuff (since we are not using white
spaces), and thus:

    Each occurrence in the input of an IFS character shall delimit a field.


In zsh each occurrence of a comma does delimit a field (4 commas, 5
fields), which to me is what POSIX says should happen.

So in this particular case it seems zsh is complying with POSIX (even
in zsh mode), and all other shells are not.

So there's no bug (at least in zsh), I just wanted to let you know
what I found, and see if you agreed with my interpretation.

Cheers.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05


-- 
Felipe Contreras








Messages sorted by: Reverse Date, Date, Thread, Author