Re: Possibly wrong handling of $_?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux