[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 04:39:17 -0600 |
Hi,
Consider this example:
IFS=,
str='foo,bar,,roo,'
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
fields.
This is not what bash does.
Shouldn't bash generate the last field? At least in POSIX mode (I
tried with `--posix` same output).
Cheers.
Obligatory stuff:
* version: 5.1.16(1)-release
* platform: x86_64 Arch Linux
* compiler: gcc 12.2.1
[1]
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
--
Felipe Contreras
- Re: IFS field splitting doesn't conform with POSIX, (continued)
- Re: IFS field splitting doesn't conform with POSIX, Oğuz İsmail Uysal, 2023/03/30
- Re: IFS field splitting doesn't conform with POSIX, Felipe Contreras, 2023/03/30
- Re: IFS field splitting doesn't conform with POSIX, Andreas Kusalananda Kähäri, 2023/03/30
- Re: IFS field splitting doesn't conform with POSIX, Oğuz İsmail Uysal, 2023/03/30
- Re: IFS field splitting doesn't conform with POSIX, Felipe Contreras, 2023/03/30
- Re: IFS field splitting doesn't conform with POSIX, Lawrence Velázquez, 2023/03/30
- Re: IFS field splitting doesn't conform with POSIX, Chet Ramey, 2023/03/31
- Re: IFS field splitting doesn't conform with POSIX, Andreas Schwab, 2023/03/30
- Re: IFS field splitting doesn't conform with POSIX, Chet Ramey, 2023/03/31
Re: IFS field splitting doesn't conform with POSIX, Chet Ramey, 2023/03/31
IFS field splitting doesn't conform with POSIX,
Felipe Contreras <=