[Top][All Lists]

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

Re: Special parameter $_ expands to a relative path

From: Greg Wooledge
Subject: Re: Special parameter $_ expands to a relative path
Date: Thu, 1 Sep 2011 08:11:51 -0400
User-agent: Mutt/

On Thu, Sep 01, 2011 at 01:15:34AM -0800, Roger wrote:
>               A  colon-separated list of file names to be checked for mail.  
> The message to be printed when mail arrives in a particular file
>               may be specified by separating the file name from the message 
> with a `?'.  When used in the text of the message, $_ expands  to
>               the name of the current mailfile.  Example:
>               MAILPATH='/var/mail/bfox?"You have mail":~/shell-mail?"$_ has 
> mail!"'
> bash-4.2_p10 doesn't say much more about $_.

That's because you're searching for the two-character string $_ instead
of magically knowing that you are supposed to be searching for the
one-character string _ under the Special Parameters section.  (I submitted
a patch for this but it was not accepted.  It's brought up on the list
a few times a year; this is one of those times.)

    Special Parameters
      _    At shell startup, set to the absolute pathname used to invoke the
           shell or shell script being executed as passed in the environment
           or argument list.  Subsequently, expands to the last argument to
           the previous command, after expansion.  Also set to the full
           pathname used to invoke 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

I'd strike the word "absolute" from that first sentence.

The original poster may be interested in this page:

http://mywiki.wooledge.org/BashFAQ/028 -- How do I determine the location
of my script?  I want to read some config files from the same place.

That sounds like what he was hoping to accomplish.  He is going to be
disappointed, unless he's willing to accept one of the "90% solutions"
that are so incredibly popular.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]