Zsh Mailing List Archive
Messages sorted by:
Re: Discrepancy in IFS handling (zsh is POSIX compliant)
On Thu, Mar 30, 2023 at 6:05 AM Lawrence Velázquez <larryv@xxxxxxx> wrote:
> On Mar 30, 2023, at 7:13 AM, Felipe Contreras <felipe.contreras@xxxxxxxxx> wrote:
> 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.
> Before the excerpt you quoted, XCU 2.6.5 says: “The shell shall treat each character of the IFS as a delimiter and use the delimiters as field terminators to split the results of parameter expansion, command substitution, and arithmetic expansion into fields.”
I was just about to mention that, and I thought I replied to you, but
So if IFS contains terminators, and not separators, this should
generate 5 fields:
printf '"%s"\n' $str
For: 'foo;' 'bar;' ';' 'roo;' ';'
In which case bash is correct, and zsh is not.
But, 'foo' doesn't contain any terminators, so it does not contain any
field, and should be dropped. Unless 1) you consider the end of the
string as a terminator, or 2) consider the terminator of the last
field as optional.
If you consider the end of the string as a terminator (1), then 'foo;'
contains two fields, not one, in which case zsh is correct. This makes
the terminators behave identically as separators.
If you consider the terminator of the last field as optional, then
bash (and other shells) are correct, but in that case what's the point
of terminators if they aren't actually going to demarcate the
*terminaton* of fields?
I think everyone can agree POSIX is not clear about this.
Messages sorted by: