From: Harald van Dijk <harald@gigawatt.nl>
To: Jilles Tjoelker <jilles@stack.nl>, Vadim Zeitlin <vz-dash@zeitlins.org>
Cc: dash@vger.kernel.org
Subject: Re: Possibly wrong handling of $_?
Date: Thu, 25 Dec 2014 23:05:24 +0100 [thread overview]
Message-ID: <549C8A24.1060309@gigawatt.nl> (raw)
In-Reply-To: <20141225143226.GA27266@stack.nl>
On 25/12/2014 15:32, Jilles Tjoelker wrote:
> On Wed, Dec 24, 2014 at 12:33:32AM +0100, Vadim Zeitlin wrote:
>> On Wed, 24 Dec 2014 00:21:09 +0100 Harald van Dijk <harald@gigawatt.nl> wrote:
>> HvD> On 23/12/2014 23:34, Vadim Zeitlin wrote:
>> HvD> > Hello,
>> HvD> >
>> HvD> > I'm not exactly sure if this is a bug because I didn't find any
>> HvD> > specification about how is this supposed to behave (to my surprise it
>> HvD> > turned out that $_ was not in POSIX), but please consider this:
>> HvD> >
>> HvD> > % zsh -c 'echo -n foo && echo $_'
>> HvD> > foofoo
>> HvD> > % bash -c 'echo -n foo && echo $_'
>> HvD> > foofoo
>> HvD> > % dash -c 'echo -n foo && echo $_'
>> HvD> > foo/usr/bin/dash
>> HvD>
>> HvD> This does come across as somewhat confusing, but $_ is really not a
>> HvD> special variable at all in dash.
>
>> Ah, this does explain it, thanks!
>
> Dash does implement $_, but only in interactive mode.
Ah, apologies. In interactive mode, it indeed implements it, but
differently from bash. In dash, only commands that specify a command
name cause $_ to be set. For example,
dash -ic 'if a=b; then c=d; else e=f; fi; echo $_'
still prints
/usr/bin/dash
(or wherever dash is installed), because if statements, and variable
assignments, have no effect on $_. In bash, this prints a blank line,
because the prior value of $_ has not survived those variable assignments.
Cheers,
Harald van Dijk
prev parent reply other threads:[~2014-12-25 22:05 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-23 22:34 Possibly wrong handling of $_? Vadim Zeitlin
2014-12-23 23:21 ` Harald van Dijk
2014-12-23 23:33 ` Re[2]: " Vadim Zeitlin
2014-12-25 14:32 ` Jilles Tjoelker
2014-12-25 22:05 ` Harald van Dijk [this message]
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=549C8A24.1060309@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.org \
--cc=jilles@stack.nl \
--cc=vz-dash@zeitlins.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.
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).