Re: [man bash] help understanding.
From: Stephen Bach (sjbach_at_users.sourceforge.net)
Date: 04/27/05
- Next message: Alan Connor: "Re: Script to insert text before a certain line"
- Previous message: Bruce Barnett: "Re: FAQ question"
- In reply to: nabis: "[man bash] help understanding."
- Next in thread: nabis: "Re: [man bash] help understanding."
- Reply: nabis: "Re: [man bash] help understanding."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 27 Apr 2005 14:02:02 -0400
Hi nabis,
nabis wrote:
> Hi!
> I need some additional explanation on section PARAMETERS subsection
> Special Parameters from the bash(1) manual page. I states:
>
> _ At shell startup, set to the absolute file name of the shell or
> shell script being executed as passed in the argument list. Subse-
> quently, expands to the last argument to the previous command,
> after expansion. Also set to the full file name of 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.
>
> If you translate it in code it will, probably, look like the following:
>
> #!/usr/bin/bash
> echo $_ # the absolute file name of the shell
> ls /home
> echo $_ # the last argument to the previous command
>
> I'd appreciate if someone could explain better or type in a line of code
> which demonstrates the following:
> "Also set to the full file name of each command executed and placed in
> the environment exported to that command."
>
> Thank you. Vitaliy.
It just means that the new process will see the $_ variable as being
the path to its executable (not as the last argument to the
command called previous to it).
For example, given a script and a short program:
foo.sh:
#!/bin/bash
echo $_
ls /
echo $_
./bar abc def ghi
echo $_
bar.c:
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char** argv) {
printf("%s\n", getenv("_"));
return 0;
}
The output from running ./foo.sh:
/bin/bash
bin dev home lost+found opt root sys usr
boot etc lib mnt proc sbin tmp var
/
./bar
ghi
- Next message: Alan Connor: "Re: Script to insert text before a certain line"
- Previous message: Bruce Barnett: "Re: FAQ question"
- In reply to: nabis: "[man bash] help understanding."
- Next in thread: nabis: "Re: [man bash] help understanding."
- Reply: nabis: "Re: [man bash] help understanding."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|