Meaning/usage of $_ in bash

VirginSnow at vfemail.net VirginSnow at vfemail.net
Wed Jul 23 16:51:18 EDT 2008


> Date: Wed, 23 Jul 2008 16:27:09 -0400
> From: "Ben Scott" <dragonhawk at gmail.com>

>   As Thomas Charon hinted at, it appears to start out set to the last
> external command, but then it gets set to the last word of the
> previous command line.  I dunno if that's "by design", or just an
> accident of implemenetation.

I think it's more along the lines of an "accident by design". :-) The
_ variable appears to be overloaded... with different meanings in
different circumstances.  Qutoing the bash man page:

       _      At  shell startup, set to the absolute file name of the shell or
              shell script being executed as  passed  in  the  argument  list.
              Subsequently,  expands to the last argument to the previous com-
              mand, after expansion.  Also set to the full file name  of  each
              command  executed and placed in the environment exported to that
              command.  When checking mail, this parameter holds the  name  of
              the mail file currently being checked.


More information about the gnhlug-discuss mailing list