[Top][All Lists]

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

IFS field splitting doesn't conform with POSIX

From: Felipe Contreras
Subject: IFS field splitting doesn't conform with POSIX
Date: Thu, 30 Mar 2023 05:12:46 -0600


Consider this example:

    printf '"%s"\n' $str

There is a discrepancy between how this is interpreted between bash
and zsh: in bash the last comma doesn't generate a field and is
ignored, in zsh a last empty field is generated. Initially I was going
to report the bug in zsh, until I read what the POSIX specification
says about field splitting [1].

If we ignore all the complexity regarding IFS white spaces (since our
IFS doesn't have them), we arrive to this item:

    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.

Again, we ignore the white space stuff, which means "each occurrence
in the input of an IFS character shall delimit a field". So if *each
occurrence* of a comma shall delimit a field, the last comma should
delimit a field. We have four commas, therefore we should have five

This is not what bash does.

Shouldn't bash generate the last field? At least in POSIX mode (I
tried with `--posix` same output).


Obligatory stuff:

* version: 5.1.16(1)-release
* platform: x86_64 Arch Linux
* compiler: gcc 12.2.1


Felipe Contreras

reply via email to

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