zsh-users
 help / color / mirror / code / Atom feed
* [bug] () { echo $#} $'' is zero
@ 2016-03-03 21:16 Ryan Wilson
  2016-03-03 22:33 ` Martijn Dekker
  2016-03-03 23:34 ` Bart Schaefer
  0 siblings, 2 replies; 4+ messages in thread
From: Ryan Wilson @ 2016-03-03 21:16 UTC (permalink / raw)
  To: zsh-users

Subject says it all. The empty string $'' is not passed to commands the same
way the empty strings "" and '' are:

    $ count () { echo $#; }
    $ count ""    # okay
    1
    $ count ''    # sure
    1
    $ count $''   # huh?
    0

Any clue as to what's going on?


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

* Re: [bug] () { echo $#} $'' is zero
  2016-03-03 21:16 [bug] () { echo $#} $'' is zero Ryan Wilson
@ 2016-03-03 22:33 ` Martijn Dekker
  2016-03-03 23:34 ` Bart Schaefer
  1 sibling, 0 replies; 4+ messages in thread
From: Martijn Dekker @ 2016-03-03 22:33 UTC (permalink / raw)
  To: zsh-users; +Cc: Ryan Wilson

Ryan Wilson schreef op 03-03-16 om 22:16:
> Subject says it all. The empty string $'' is not passed to commands the same
> way the empty strings "" and '' are:
[...]
> Any clue as to what's going on?

Apparently, zsh subjects $'' to empty removal[*] as if it were an
unquoted parameter substitution for an empty variable.

This form of quoting is not standardised yet, but this behaviour is
unlike bash, ksh93, mksh and FreeBSD /bin/sh, so I would agree it's a
bug in zsh.

C-style escape $'quoting' looks likely to be added to the next edition
of the POSIX standard (with FreeBSD /bin/sh recently adding support for
it), so now would be a particularly good time to fix it.

- M.

[*] POSIX: "If the complete expansion appropriate for a word results in
an empty field, that empty field shall be deleted from the list of
fields that form the completely expanded command, unless the original
word contained single-quote or double-quote characters."
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06


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

* Re: [bug] () { echo $#} $'' is zero
  2016-03-03 21:16 [bug] () { echo $#} $'' is zero Ryan Wilson
  2016-03-03 22:33 ` Martijn Dekker
@ 2016-03-03 23:34 ` Bart Schaefer
  2016-03-04  7:16   ` Philippe Troin
  1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-03-03 23:34 UTC (permalink / raw)
  To: zsh-users

On Mar 3,  3:16pm, Ryan Wilson wrote:
} Subject: [bug] () { echo $#} $'' is zero
}
} Subject says it all. The empty string $'' is not passed to commands the same
} way the empty strings "" and '' are:

$'...' is not a quoted expression, it's a substitution (at least as far
as zsh is concerned).  It behaves like expanding a $parameter reference,
except that the value is the string inside the '...' part.

Thus
    set -- $''
is more akin to
    x=''
    set -- $x
than to
    set -- ''

This does appear to be out of step with other shells.  Follow-ups to
zsh-workers.


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

* Re: [bug] () { echo $#} $'' is zero
  2016-03-03 23:34 ` Bart Schaefer
@ 2016-03-04  7:16   ` Philippe Troin
  0 siblings, 0 replies; 4+ messages in thread
From: Philippe Troin @ 2016-03-04  7:16 UTC (permalink / raw)
  To: zsh-users

On Thu, 2016-03-03 at 15:34 -0800, Bart Schaefer wrote:
> On Mar 3,  3:16pm, Ryan Wilson wrote:
> } Subject: [bug] () { echo $#} $'' is zero
> }
> } Subject says it all. The empty string $'' is not passed to commands the same
> } way the empty strings "" and '' are:
> 
> $'...' is not a quoted expression, it's a substitution (at least as far
> as zsh is concerned).  It behaves like expanding a $parameter reference,
> except that the value is the string inside the '...' part.
> 
> Thus
>     set -- $''
> is more akin to
>     x=''
>     set -- $x
> than to
>     set -- ''

Well not really.
        % echo $param $'<\n>'
        value <
        >
        % echo "$param $'<\n>'"
        value $'<\n>'

It behaves like $parameter, but definitely not within double
quotes... ;-)

Phil.


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

end of thread, other threads:[~2016-03-04  7:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-03 21:16 [bug] () { echo $#} $'' is zero Ryan Wilson
2016-03-03 22:33 ` Martijn Dekker
2016-03-03 23:34 ` Bart Schaefer
2016-03-04  7:16   ` Philippe Troin

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