Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bash _ (underscore) var. name

560 views
Skip to first unread message

andru

unread,
Oct 25, 2010, 6:53:13 PM10/25/10
to
This resolves one question I had during office hours today, and
explains why attempts to assign var _=blah gave wierd results.
This is quite esoteric so don't read it if you don't care personally!

On p. 15 of the notes, a syntax for variable names is given
which implies that _ (underscore) alone is a valid variable name.
In fact, it is valid, but it is also reserved by bash, and has the
following special meaning:

$_ or ${_}
At shell startup, set to the absolute pathname used to invoke
the shell or shell script being executed as passed in the envi-
ronment 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 check
ing mail, this parameter holds the name of the mail file cur-
rently being checked.
-- bash(1) man page

-Andrew

Peter A. Buhr

unread,
Oct 25, 2010, 8:18:30 PM10/25/10
to
In article <ia51op$7m7$1...@rumours.uwaterloo.ca>,

In defence of the course notes, it does state:

Some identifiers are reserved (e.g., if, while), and hence, keywords.

which varies depending on the shell. So the name "_" in bash is reserved.
I checked, and I can create a variable named "_" in the bourne shell (sh).

0 new messages