bug-bash
[Top][All Lists]
Advanced

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

Documentation for $_ in "Special Parameters" section


From: Glenn Morris
Subject: Documentation for $_ in "Special Parameters" section
Date: Mon, 7 Feb 2005 17:31:02 +0000

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/scratch/gmorris/software/share/locale' 
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib  
-I/scratch/gmorris/software/include -g -O2
uname output: Linux xpc14.ast.cam.ac.uk 2.6.10-1.9_FC2 #1 Thu Jan 13 17:54:57 
EST 2005 i686 athlon i386 GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 3.0
Patch Level: 16
Release Status: release

Description:

The documentation for $_ in the bash info page seems misleading to me.
Quoting:

`_'
     (An underscore.)  At shell startup, set to the absolute filename
     of the shell or shell script being executed as passed in the
     argument list.  Subsequently, expands to the last argument to the
     previous command, after expansion.  Also set to the full pathname
     of each command executed and placed in the environment exported to
     that command.

Two points:

1) "set to the absolute filename of the shell or shell script"

It's not the absolute filename, eg:

cat - > ~/go.bash <<'EOF'
#!/bin/bash
echo $_
EOF

( cd /bin; ./bash ~/go.bash )   => ./bash


On a susbsidiary point, I don't see how it can ever be set to the
shell _script_ filename, eg:

chmod +x go.bash
./go.bash               => /bin/bash

The "or shell script" in the documentation makes me think I can expect
to get "./go.bash" here.


2). "Also set to the full pathname of each command executed"

Again, it's not really the full pathname; but rather than pathname
exactly as typed, eg:

cat - > go.awk <<'EOF'
#!/usr/bin/gawk -f
BEGIN \
{
    print ENVIRON["_"]
    exit
}
EOF

chmod +x go.awk
./go.awk                 => ./go.awk
(cd bin; ../go.awk)      => ../go.awk




reply via email to

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