zsh-users
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: "Lawrence Velázquez" <larryv@zsh.org>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Discrepancy in IFS handling (zsh is *not* POSIX compliant)
Date: Thu, 30 Mar 2023 06:10:48 -0600	[thread overview]
Message-ID: <CAMP44s2KB_DbemKs9jFu=0yy06DaC+H1W2SiueEoQ-rtHOp-NA@mail.gmail.com> (raw)
In-Reply-To: <D5349F8B-5D85-4E62-9FBC-520181FEC6A9@zsh.org>

On Thu, Mar 30, 2023 at 6:05 AM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> On Mar 30, 2023, at 7:13 AM, Felipe Contreras <felipe.contreras@gmail.com> 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.”
>
> The bash/dash/ksh behavior is not unreasonable if the phrase “field terminators” is interpreted strictly.
>
> In any case, I believe the standard intends to describe the ksh behavior:

Yes, I was about to click send to point that out.

So if IFS contains terminators, and not separators, this should
generate 5 fields:

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

For: 'foo;' 'bar;' ';' 'roo;' ';'

In which case bash is correct, zsh generates 6 fields, so it's not.

Seems weird that a variable called Internal Field Separator is not a
*separator*, but a terminator.

I'm changing the subject to reflect that.

Cheers.

-- 
Felipe Contreras


  reply	other threads:[~2023-03-30 12:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 11:11 Discrepancy in IFS handling (zsh is " Felipe Contreras
2023-03-30 12:05 ` Lawrence Velázquez
2023-03-30 12:10   ` Felipe Contreras [this message]
2023-03-30 14:49     ` Discrepancy in IFS handling (zsh is *not* " Ray Andrews
2023-03-30 15:09       ` Felipe Contreras
2023-03-30 15:31         ` Ray Andrews
2023-03-30 14:57     ` Bart Schaefer
2023-03-30 15:34       ` Felipe Contreras
2023-03-31 20:16   ` Discrepancy in IFS handling (zsh is " Felipe Contreras
2023-04-01 19:20     ` Lawrence Velázquez
2023-03-31 16:38 ` Thomas Paulsen
2023-03-31 20:18   ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAMP44s2KB_DbemKs9jFu=0yy06DaC+H1W2SiueEoQ-rtHOp-NA@mail.gmail.com' \
    --to=felipe.contreras@gmail.com \
    --cc=larryv@zsh.org \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).