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: Re: Discrepancy in IFS handling (zsh is POSIX compliant)
Date: Fri, 31 Mar 2023 14:16:06 -0600	[thread overview]
Message-ID: <CAMP44s0P8J-qfc8sO9E_kxg81sYAvxRGmdknUqC2ntH_FVO_pg@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.”

I was just about to mention that, and I thought I replied to you, but
apparently not.

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, 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.

-- 
Felipe Contreras


  parent reply	other threads:[~2023-03-31 20:17 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-30 11:11 Felipe Contreras
2023-03-30 12:05 ` Lawrence Velázquez
2023-03-30 12:10   ` Discrepancy in IFS handling (zsh is *not* " Felipe Contreras
2023-03-30 14:49     ` 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   ` Felipe Contreras [this message]
2023-04-01 19:20     ` Discrepancy in IFS handling (zsh is " 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=CAMP44s0P8J-qfc8sO9E_kxg81sYAvxRGmdknUqC2ntH_FVO_pg@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).