This is just a nit but I've never understood the meaning/usage
of the $_ variable in bash.  I did RTFM and it says:

 "When bash invokes an external command, the variable $_ is set to
  the full file name of the command and passed to that command in its
  environment."

...which seems to describe one piece of how it actually works in one
situation.  For example, if I create and execute a shell script thus:

   echo '#!/bin/bash'      > /tmp/wtf.sh
   echo 'echo _ is $_'    >> /tmp/wtf.sh
   echo 'date'            >> /tmp/wtf.sh
   echo 'echo _ is $_'    >> /tmp/wtf.sh
   echo ':'               >> /tmp/wtf.sh
   echo 'echo _ is $_'    >> /tmp/wtf.sh
   echo 'echo _ is $_'    >> /tmp/wtf.sh
   echo 'echo Hi,Mom'     >> /tmp/wtf.sh
   echo 'echo _ is $_'    >> /tmp/wtf.sh
   echo 'set > /dev/null' >> /tmp/wtf.sh
   echo 'echo _ is $_'    >> /tmp/wtf.sh
   chmod +x                  /tmp/wtf.sh
   /tmp/wtf.sh

...I see this:

   _ is /tmp/wtf.sh
   Wed Jul 23 12:53:08 EDT 2008
   _ is date
   _ is :
   _ is :
   _ is set
   Hi,Mom
   _ is Hi,Mom

...where the first line of output seems to show it working as
described but subsequent values seem to instead show the last
command executed, builtin or external.  But not consistently -
why doesn't it ever take on the value of "echo" but it does take
on the values of "set" and the ":" no-op...?  And it takes on the
value of "Hi,Mom" which is a parameter rather than a command.  (?)

It seems to be just as weird when used interactively so I'm
wondering if this is a simple case of b0rken design/implementation
or if there's some method to the madness that'll help me
understand its behavior/purpose.
 
_______________________________________________
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/

Reply via email to