From: Harald van Dijk <harald@gigawatt.nl>
To: Vadim Zeitlin <vz-dash@zeitlins.org>
Cc: dash@vger.kernel.org
Subject: Re: Possibly wrong handling of $_?
Date: Wed, 24 Dec 2014 00:21:09 +0100 [thread overview]
Message-ID: <5499F8E5.205@gigawatt.nl> (raw)
In-Reply-To: <E1Y3Y2d-000276-SL@smtp.tt-solutions.com>
On 23/12/2014 23:34, Vadim Zeitlin wrote:
> Hello,
>
> I'm not exactly sure if this is a bug because I didn't find any
> specification about how is this supposed to behave (to my surprise it
> turned out that $_ was not in POSIX), but please consider this:
>
> % zsh -c 'echo -n foo && echo $_'
> foofoo
> % bash -c 'echo -n foo && echo $_'
> foofoo
> % dash -c 'echo -n foo && echo $_'
> foo/usr/bin/dash
This does come across as somewhat confusing, but $_ is really not a
special variable at all in dash. The shell you're using to launch dash
does make it a special variable. That shell puts _ in the environment,
which dash then picks up, and ignores, other than making it available as $_.
You can see what your usual shell is doing by testing with other
commands: just run
env | grep '^_='
and you'll probably see
_=/usr/bin/env
It works the same way when starting dash.
> I've tested several different versions of zsh (4 and 5) and bash (3 and 4)
> and dash 0.5.5 and 0.5.7 from Debian and they all produced the results as
> above.
>
> Shouldn't dash follow the other shells here?
> VZ
If dash did something special with $_, then I agree it would be nice if
it would be somewhat compatible with other shells. If dash simply does
not implement a feature, that feature is not required by any standard,
and that feature is not widely used, then I suspect there won't be a lot
of interest in implementing that feature.
Don't be put off by that, though. You are free, of course, if you feel
so, to attempt to convince people $_ is an important feature that all
shells should implement. If you have compelling use cases, if it solves
real problems, and if many other shells already implement it, you might
even get it standardised. I have never seen a need for it, but that's
just me speaking from personal experience, others may feel differently.
Cheers,
Harald van Dijk
next prev parent reply other threads:[~2014-12-23 23:21 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 [this message]
2014-12-23 23:33 ` Re[2]: " Vadim Zeitlin
2014-12-25 14:32 ` Jilles Tjoelker
2014-12-25 22:05 ` Harald van Dijk
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=5499F8E5.205@gigawatt.nl \
--to=harald@gigawatt.nl \
--cc=dash@vger.kernel.org \
--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