Re: what is $_ in shell

On Friday 10 October 2008 13:24, parag_paul@xxxxxxxxxxx wrote:

I saw this usage in one of the shell script in house
if ( $_ != ?

What is $_

In shell, the would just mean "the variable whose name is _".
In bash (and maybe other shells) that is a special variable:

_ 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 checked.

Note that it's possible that you are looking at a Perl script, where $_ is
also special.