zsh-users
 help / Atom feed
* zsh in sh compatibility mode splits IFS slightly differently from other shells
@ 2019-07-24  8:02 Avery Pennarun
  2019-07-24 16:30 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Avery Pennarun @ 2019-07-24  8:02 UTC (permalink / raw)
  To: zsh-users

Hi all,

I think this may be a known bug, as you can see it documented here:
https://www.in-ulm.de/~mascheck/various/ifs/

However, it bit users of one of my scripts lately
(https://github.com/apenwarr/redo/blob/master/minimal/do) because it
was accidentally depending on the non-sh behaviour.

Simple test:

emulate sh
x="/a/b/c/"
IFS=/
f() {
    echo "$2" "$#"
}
f $x

On zsh, this prints:
   a 5

on bash, dash, mksh, ksh93, and posh (at least), this prints:
   a 4

I've already worked around the problem in my script, but it would be
nice if nobody ever has to experience this again. Would it be possible
to change zsh to match other shells' behaviour, at least when in sh
compatibility mode?

Thanks,

Avery

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: zsh in sh compatibility mode splits IFS slightly differently from other shells
  2019-07-24  8:02 zsh in sh compatibility mode splits IFS slightly differently from other shells Avery Pennarun
@ 2019-07-24 16:30 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2019-07-24 16:30 UTC (permalink / raw)
  To: Avery Pennarun; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 847 bytes --]

On Wed, Jul 24, 2019, 1:03 AM Avery Pennarun <apenwarr@gmail.com> wrote:

> Hi all,
>
> I think this may be a known bug, as you can see it documented here:
> https://www.in-ulm.de/~mascheck/various/ifs/
>
> However, it bit users of one of my scripts lately
> (https://github.com/apenwarr/redo/blob/master/minimal/do) because it
> was accidentally depending on the non-sh behaviour.
>
> Simple test:
>
> emulate sh
> x="/a/b/c/"
> IFS=/
> f() {
>     echo "$2" "$#"
> }
> f $x
>
> On zsh, this prints:
>    a 5
>
> on bash, dash, mksh, ksh93, and posh (at least), this prints:
>    a 4
>
> I've already worked around the problem in my script, but it would be
> nice if nobody ever has to experience this again. Would it be possible
> to change zsh to match other shells' behaviour, at least when in sh
> compatibility mode?
>
> Thanks,
>
> Avery
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-24  8:02 zsh in sh compatibility mode splits IFS slightly differently from other shells Avery Pennarun
2019-07-24 16:30 ` Bart Schaefer

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/ public-inbox