Understand the meaning of `$_`What does $_, and $0 represent in sourced bash?When is `_` dropped out of the...
Compaq Portable vs IBM 5155 Portable PC
How to politely tell someone they did not hit "reply to all" in an email?
What does ${!#} mean in Shell scripting?
Pirate democracy at its finest
Is the field of q-series 'dead'?
Is it rude to call a professor by their last name with no prefix in a non-academic setting?
Apt - strange requests to d16r8ew072anqo.cloudfront.net:80
Which European Languages are not Indo-European?
Where have Brexit voters gone?
Does pair production happen even when the photon is around a neutron?
Remove CiviCRM and Drupal links / banner on profile form
The art of clickbait captions
NIntegrate doesn't evaluate
Is it true that cut time means "play twice as fast as written"?
Is there an online tool which supports shared writing?
Can I connect my older mathematica front-end to the free wolfram engine?
How to cut a climbing rope?
What could a self-sustaining lunar colony slowly lose that would ultimately prove fatal?
Why do Russians almost not use verbs of possession akin to "have"?
Could a 19.25mm revolver actually exist?
How to reverse input order?
Defining the standard model of PA so that a space alien could understand
Why did the person in charge of a principality not just declare themself king?
Is it truly impossible to tell what a CPU is doing?
Understand the meaning of `$_`
What does $_, and $0 represent in sourced bash?When is `_` dropped out of the environment?When is `_` an environment variable of a bash shell?Usage of `_` as an environment variable passed to a commandWhat can we use “mail” for?What does `echo $_` output after `export foo=bar`?If there is no assignment of environment variable following `env`, what kind of environment is a command executed with?Why is variable assignment preceding command ignored?Can 'ssh <host> <command>' be configured to always load server-side startup files?$_ vs !$. Last argument of the preceding command and output redirectionWhat is the meaning of $0 in the Bash shellWhy does `bash -c 'echo $0 ' ` output “bash”?What does `echo $_` output after `export foo=bar`?What is the execution environment where `command [arguments]` in `exec command [arguments]` runs?Why is this environment variable not set up?Are all the shell options not inherited by scripts?When is `_` an environment variable of a bash shell?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
Could you explain the following sentences from Bash manual about $_
, especially the parts in bold, maybe with some examples?
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.
bash
add a comment |
Could you explain the following sentences from Bash manual about $_
, especially the parts in bold, maybe with some examples?
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.
bash
3
-1 question unclear & not thoroughly researched. What have you tried? Where did your expectations misalign with the text? Do you not honestly understand the word 'subsequently'? If a new user were to ask this same question I would have the same questions of them (despite my similar innate curiosity as to exactly how things work).
– Jeff Schaller♦
May 2 '16 at 2:41
add a comment |
Could you explain the following sentences from Bash manual about $_
, especially the parts in bold, maybe with some examples?
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.
bash
Could you explain the following sentences from Bash manual about $_
, especially the parts in bold, maybe with some examples?
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.
bash
bash
edited May 1 '16 at 21:03
jasonwryan
51.5k14136190
51.5k14136190
asked May 1 '16 at 20:52
TimTim
29.7k82274507
29.7k82274507
3
-1 question unclear & not thoroughly researched. What have you tried? Where did your expectations misalign with the text? Do you not honestly understand the word 'subsequently'? If a new user were to ask this same question I would have the same questions of them (despite my similar innate curiosity as to exactly how things work).
– Jeff Schaller♦
May 2 '16 at 2:41
add a comment |
3
-1 question unclear & not thoroughly researched. What have you tried? Where did your expectations misalign with the text? Do you not honestly understand the word 'subsequently'? If a new user were to ask this same question I would have the same questions of them (despite my similar innate curiosity as to exactly how things work).
– Jeff Schaller♦
May 2 '16 at 2:41
3
3
-1 question unclear & not thoroughly researched. What have you tried? Where did your expectations misalign with the text? Do you not honestly understand the word 'subsequently'? If a new user were to ask this same question I would have the same questions of them (despite my similar innate curiosity as to exactly how things work).
– Jeff Schaller♦
May 2 '16 at 2:41
-1 question unclear & not thoroughly researched. What have you tried? Where did your expectations misalign with the text? Do you not honestly understand the word 'subsequently'? If a new user were to ask this same question I would have the same questions of them (despite my similar innate curiosity as to exactly how things work).
– Jeff Schaller♦
May 2 '16 at 2:41
add a comment |
3 Answers
3
active
oldest
votes
I agree it's not very clear.
1. At shell startup,
if the
_
variable was in the environment thatbash
received, thenbash
leaves it untouched.
In particular, if that
bash
shell was invoked by anotherbash
shell (thoughzsh
,yash
and someksh
implementations also do
it), then thatbash
shell will have set the_
environment
variable to the path of the command being executed (that's the 3rd
point in your question). For instance, ifbash
is invoked to
interpret a script as a result of anotherbash
shell interpreting:
bash-script some args
That
bash
will have passed_=/path/to/bash-scrip
in the
environment given tobash-script
, and that's what the initial
value of the$_
bash
variable will be in thebash
shell that
interprets that script.
$ env -i _=whatever bash -c 'echo "$_"'
whatever
Now, if the invoking application doesn't pass a
_
environment
variable, the invokedbash
shell will initialise$_
to theargv[0]
it receives
itself which could bebash
, or/path/to/bash
or
/path/to/some-script
or anything else (in the example above, that
would be/bin/bash
if the she-bang of the script was#! /bin/bash
or/path/to/bash-script
depending on the
system).
So that text is misleading as it describes the behaviour of the
caller whichbash
has no control over. The application that invoked
bash
may very well not set$_
at all (in practice, only some
shells and a few rare interactive applications do,execlp()
doesn't
for instance), or it could use it for something completely different
(for instanceksh93
sets it to*pid*/path/to/command
).
$ env bash -c 'echo "$_"'
/usr/bin/env (env did not set it to /bin/bash, so the value we
get is the one passed to env by my interactive shell)
$ ksh93 -c 'bash -c "echo $_"'
*20042*/bin/bash
2. Subsequently
The Subsequently is not very clear either. In practice, that's as soon as bash
interprets a simple command in the current shell environment.
In the case of an interactive shell, that will be on the first simple command interpreted from
/etc/bash.bashrc
for instance.
For instance, at the prompt of an interactive shell:
$ echo "$_"
] (the last arg of the last command from my ~/.bashrc)
$ f() { echo test; }
$ echo "$_"
] (the command-line before had no simple command, so we get
the last argument of that previous echo commandline)
$ (: test)
$ echo "$_"
] (simple command, but in a sub-shell environment)
$ : test
$ echo "$_"
test
For a non-interactive shell, it would be the first command in
$BASH_ENV
or of the code fed to that shell if$BASH_ENV
is not
set.
3. When Bash executes a command
The third point is something different and is hinted in the discussion above.
bash
, like a few other shells will pass a _
environment variable to commands it executes that contains the path that bash
used as the first argument to the execve()
system calls.
$ env | grep '^_'
_=/usr/bin/env
4. When checking mail
The fourth point is described in more details in the description of the MAILPATH
variable:
'MAILPATH'
A colon-separated list of filenames which the shell periodically
checks for new mail.
Each list entry can specify the message that
is printed when new mail arrives in the mail file by separating the
filename from the message with a '?'.
When used in the text of the
message, '$_' expands to the name of the current mail file.
Example:
$ MAILCHECK=1 MAILPATH='/tmp/a?New mail in <$_>' bash
bash$ echo test >> /tmp/a
New mail in </tmp/a>
add a comment |
Try this simple example:
echo "$_"
echo "test"
echo "$_"
Run it by giving the absolute path (/home/$USERNAME/test.sh
); output:
/home/$USERNAME/test.sh
test
test
First $_
contains the path you used to invoke the script and the second one contains the first argument to the middle echo
.
For the third item in the list, if you start a new terminal and type echo $_
it will show the variable containing the PATH
which is usually used to lookup and invoke commands (in my Ubuntu machine) in a normal shell or absolute path to your .bashrs
file in a login shell.
For the item four from bash man page:
When used in the text of the message,
$_
expands to the name of the
current mailfile.
Thanks. (1) can you explain the third case with examples? (2) When I open a new gnome terminal tab, the output ofecho $_
isEDITOR
, and why is it? Which case does it follow? (3) Can you given an example of how to check mails, and of using$_
in this case?
– Tim
May 2 '16 at 0:00
Open your.bashrc
and comment out every line there. Keep only a single line containing a command likeecho "test"
or similar. Save and close. Then runbash
and immediatelyecho $_
. This last echo should print test in the output.
– coffeMug
May 2 '16 at 6:50
For the mail part I have not used Unix mail and don't have a working mail installed on my system now so cannot give you example. But should be obvious if you follow the description ofMAILPATH
in linuxcommand.org/lc3_man_pages/bash1.html
– coffeMug
May 2 '16 at 7:18
1
FYI, the canonical, up-to-date version of the bash manual is: gnu.org/software/bash/manual/bashref.html . It's version 4.3 while the linuxcommand page was 4.1.
– Jeff Schaller♦
May 2 '16 at 9:47
add a comment |
For case 2, an example is worth a thousand words:
mkdir my_long_dir
cd $_
Does what you'd guess / hope for. Gives me a simple placeholder when I'm on the command line to save me having to repeate myself.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f280453%2funderstand-the-meaning-of%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
I agree it's not very clear.
1. At shell startup,
if the
_
variable was in the environment thatbash
received, thenbash
leaves it untouched.
In particular, if that
bash
shell was invoked by anotherbash
shell (thoughzsh
,yash
and someksh
implementations also do
it), then thatbash
shell will have set the_
environment
variable to the path of the command being executed (that's the 3rd
point in your question). For instance, ifbash
is invoked to
interpret a script as a result of anotherbash
shell interpreting:
bash-script some args
That
bash
will have passed_=/path/to/bash-scrip
in the
environment given tobash-script
, and that's what the initial
value of the$_
bash
variable will be in thebash
shell that
interprets that script.
$ env -i _=whatever bash -c 'echo "$_"'
whatever
Now, if the invoking application doesn't pass a
_
environment
variable, the invokedbash
shell will initialise$_
to theargv[0]
it receives
itself which could bebash
, or/path/to/bash
or
/path/to/some-script
or anything else (in the example above, that
would be/bin/bash
if the she-bang of the script was#! /bin/bash
or/path/to/bash-script
depending on the
system).
So that text is misleading as it describes the behaviour of the
caller whichbash
has no control over. The application that invoked
bash
may very well not set$_
at all (in practice, only some
shells and a few rare interactive applications do,execlp()
doesn't
for instance), or it could use it for something completely different
(for instanceksh93
sets it to*pid*/path/to/command
).
$ env bash -c 'echo "$_"'
/usr/bin/env (env did not set it to /bin/bash, so the value we
get is the one passed to env by my interactive shell)
$ ksh93 -c 'bash -c "echo $_"'
*20042*/bin/bash
2. Subsequently
The Subsequently is not very clear either. In practice, that's as soon as bash
interprets a simple command in the current shell environment.
In the case of an interactive shell, that will be on the first simple command interpreted from
/etc/bash.bashrc
for instance.
For instance, at the prompt of an interactive shell:
$ echo "$_"
] (the last arg of the last command from my ~/.bashrc)
$ f() { echo test; }
$ echo "$_"
] (the command-line before had no simple command, so we get
the last argument of that previous echo commandline)
$ (: test)
$ echo "$_"
] (simple command, but in a sub-shell environment)
$ : test
$ echo "$_"
test
For a non-interactive shell, it would be the first command in
$BASH_ENV
or of the code fed to that shell if$BASH_ENV
is not
set.
3. When Bash executes a command
The third point is something different and is hinted in the discussion above.
bash
, like a few other shells will pass a _
environment variable to commands it executes that contains the path that bash
used as the first argument to the execve()
system calls.
$ env | grep '^_'
_=/usr/bin/env
4. When checking mail
The fourth point is described in more details in the description of the MAILPATH
variable:
'MAILPATH'
A colon-separated list of filenames which the shell periodically
checks for new mail.
Each list entry can specify the message that
is printed when new mail arrives in the mail file by separating the
filename from the message with a '?'.
When used in the text of the
message, '$_' expands to the name of the current mail file.
Example:
$ MAILCHECK=1 MAILPATH='/tmp/a?New mail in <$_>' bash
bash$ echo test >> /tmp/a
New mail in </tmp/a>
add a comment |
I agree it's not very clear.
1. At shell startup,
if the
_
variable was in the environment thatbash
received, thenbash
leaves it untouched.
In particular, if that
bash
shell was invoked by anotherbash
shell (thoughzsh
,yash
and someksh
implementations also do
it), then thatbash
shell will have set the_
environment
variable to the path of the command being executed (that's the 3rd
point in your question). For instance, ifbash
is invoked to
interpret a script as a result of anotherbash
shell interpreting:
bash-script some args
That
bash
will have passed_=/path/to/bash-scrip
in the
environment given tobash-script
, and that's what the initial
value of the$_
bash
variable will be in thebash
shell that
interprets that script.
$ env -i _=whatever bash -c 'echo "$_"'
whatever
Now, if the invoking application doesn't pass a
_
environment
variable, the invokedbash
shell will initialise$_
to theargv[0]
it receives
itself which could bebash
, or/path/to/bash
or
/path/to/some-script
or anything else (in the example above, that
would be/bin/bash
if the she-bang of the script was#! /bin/bash
or/path/to/bash-script
depending on the
system).
So that text is misleading as it describes the behaviour of the
caller whichbash
has no control over. The application that invoked
bash
may very well not set$_
at all (in practice, only some
shells and a few rare interactive applications do,execlp()
doesn't
for instance), or it could use it for something completely different
(for instanceksh93
sets it to*pid*/path/to/command
).
$ env bash -c 'echo "$_"'
/usr/bin/env (env did not set it to /bin/bash, so the value we
get is the one passed to env by my interactive shell)
$ ksh93 -c 'bash -c "echo $_"'
*20042*/bin/bash
2. Subsequently
The Subsequently is not very clear either. In practice, that's as soon as bash
interprets a simple command in the current shell environment.
In the case of an interactive shell, that will be on the first simple command interpreted from
/etc/bash.bashrc
for instance.
For instance, at the prompt of an interactive shell:
$ echo "$_"
] (the last arg of the last command from my ~/.bashrc)
$ f() { echo test; }
$ echo "$_"
] (the command-line before had no simple command, so we get
the last argument of that previous echo commandline)
$ (: test)
$ echo "$_"
] (simple command, but in a sub-shell environment)
$ : test
$ echo "$_"
test
For a non-interactive shell, it would be the first command in
$BASH_ENV
or of the code fed to that shell if$BASH_ENV
is not
set.
3. When Bash executes a command
The third point is something different and is hinted in the discussion above.
bash
, like a few other shells will pass a _
environment variable to commands it executes that contains the path that bash
used as the first argument to the execve()
system calls.
$ env | grep '^_'
_=/usr/bin/env
4. When checking mail
The fourth point is described in more details in the description of the MAILPATH
variable:
'MAILPATH'
A colon-separated list of filenames which the shell periodically
checks for new mail.
Each list entry can specify the message that
is printed when new mail arrives in the mail file by separating the
filename from the message with a '?'.
When used in the text of the
message, '$_' expands to the name of the current mail file.
Example:
$ MAILCHECK=1 MAILPATH='/tmp/a?New mail in <$_>' bash
bash$ echo test >> /tmp/a
New mail in </tmp/a>
add a comment |
I agree it's not very clear.
1. At shell startup,
if the
_
variable was in the environment thatbash
received, thenbash
leaves it untouched.
In particular, if that
bash
shell was invoked by anotherbash
shell (thoughzsh
,yash
and someksh
implementations also do
it), then thatbash
shell will have set the_
environment
variable to the path of the command being executed (that's the 3rd
point in your question). For instance, ifbash
is invoked to
interpret a script as a result of anotherbash
shell interpreting:
bash-script some args
That
bash
will have passed_=/path/to/bash-scrip
in the
environment given tobash-script
, and that's what the initial
value of the$_
bash
variable will be in thebash
shell that
interprets that script.
$ env -i _=whatever bash -c 'echo "$_"'
whatever
Now, if the invoking application doesn't pass a
_
environment
variable, the invokedbash
shell will initialise$_
to theargv[0]
it receives
itself which could bebash
, or/path/to/bash
or
/path/to/some-script
or anything else (in the example above, that
would be/bin/bash
if the she-bang of the script was#! /bin/bash
or/path/to/bash-script
depending on the
system).
So that text is misleading as it describes the behaviour of the
caller whichbash
has no control over. The application that invoked
bash
may very well not set$_
at all (in practice, only some
shells and a few rare interactive applications do,execlp()
doesn't
for instance), or it could use it for something completely different
(for instanceksh93
sets it to*pid*/path/to/command
).
$ env bash -c 'echo "$_"'
/usr/bin/env (env did not set it to /bin/bash, so the value we
get is the one passed to env by my interactive shell)
$ ksh93 -c 'bash -c "echo $_"'
*20042*/bin/bash
2. Subsequently
The Subsequently is not very clear either. In practice, that's as soon as bash
interprets a simple command in the current shell environment.
In the case of an interactive shell, that will be on the first simple command interpreted from
/etc/bash.bashrc
for instance.
For instance, at the prompt of an interactive shell:
$ echo "$_"
] (the last arg of the last command from my ~/.bashrc)
$ f() { echo test; }
$ echo "$_"
] (the command-line before had no simple command, so we get
the last argument of that previous echo commandline)
$ (: test)
$ echo "$_"
] (simple command, but in a sub-shell environment)
$ : test
$ echo "$_"
test
For a non-interactive shell, it would be the first command in
$BASH_ENV
or of the code fed to that shell if$BASH_ENV
is not
set.
3. When Bash executes a command
The third point is something different and is hinted in the discussion above.
bash
, like a few other shells will pass a _
environment variable to commands it executes that contains the path that bash
used as the first argument to the execve()
system calls.
$ env | grep '^_'
_=/usr/bin/env
4. When checking mail
The fourth point is described in more details in the description of the MAILPATH
variable:
'MAILPATH'
A colon-separated list of filenames which the shell periodically
checks for new mail.
Each list entry can specify the message that
is printed when new mail arrives in the mail file by separating the
filename from the message with a '?'.
When used in the text of the
message, '$_' expands to the name of the current mail file.
Example:
$ MAILCHECK=1 MAILPATH='/tmp/a?New mail in <$_>' bash
bash$ echo test >> /tmp/a
New mail in </tmp/a>
I agree it's not very clear.
1. At shell startup,
if the
_
variable was in the environment thatbash
received, thenbash
leaves it untouched.
In particular, if that
bash
shell was invoked by anotherbash
shell (thoughzsh
,yash
and someksh
implementations also do
it), then thatbash
shell will have set the_
environment
variable to the path of the command being executed (that's the 3rd
point in your question). For instance, ifbash
is invoked to
interpret a script as a result of anotherbash
shell interpreting:
bash-script some args
That
bash
will have passed_=/path/to/bash-scrip
in the
environment given tobash-script
, and that's what the initial
value of the$_
bash
variable will be in thebash
shell that
interprets that script.
$ env -i _=whatever bash -c 'echo "$_"'
whatever
Now, if the invoking application doesn't pass a
_
environment
variable, the invokedbash
shell will initialise$_
to theargv[0]
it receives
itself which could bebash
, or/path/to/bash
or
/path/to/some-script
or anything else (in the example above, that
would be/bin/bash
if the she-bang of the script was#! /bin/bash
or/path/to/bash-script
depending on the
system).
So that text is misleading as it describes the behaviour of the
caller whichbash
has no control over. The application that invoked
bash
may very well not set$_
at all (in practice, only some
shells and a few rare interactive applications do,execlp()
doesn't
for instance), or it could use it for something completely different
(for instanceksh93
sets it to*pid*/path/to/command
).
$ env bash -c 'echo "$_"'
/usr/bin/env (env did not set it to /bin/bash, so the value we
get is the one passed to env by my interactive shell)
$ ksh93 -c 'bash -c "echo $_"'
*20042*/bin/bash
2. Subsequently
The Subsequently is not very clear either. In practice, that's as soon as bash
interprets a simple command in the current shell environment.
In the case of an interactive shell, that will be on the first simple command interpreted from
/etc/bash.bashrc
for instance.
For instance, at the prompt of an interactive shell:
$ echo "$_"
] (the last arg of the last command from my ~/.bashrc)
$ f() { echo test; }
$ echo "$_"
] (the command-line before had no simple command, so we get
the last argument of that previous echo commandline)
$ (: test)
$ echo "$_"
] (simple command, but in a sub-shell environment)
$ : test
$ echo "$_"
test
For a non-interactive shell, it would be the first command in
$BASH_ENV
or of the code fed to that shell if$BASH_ENV
is not
set.
3. When Bash executes a command
The third point is something different and is hinted in the discussion above.
bash
, like a few other shells will pass a _
environment variable to commands it executes that contains the path that bash
used as the first argument to the execve()
system calls.
$ env | grep '^_'
_=/usr/bin/env
4. When checking mail
The fourth point is described in more details in the description of the MAILPATH
variable:
'MAILPATH'
A colon-separated list of filenames which the shell periodically
checks for new mail.
Each list entry can specify the message that
is printed when new mail arrives in the mail file by separating the
filename from the message with a '?'.
When used in the text of the
message, '$_' expands to the name of the current mail file.
Example:
$ MAILCHECK=1 MAILPATH='/tmp/a?New mail in <$_>' bash
bash$ echo test >> /tmp/a
New mail in </tmp/a>
edited Aug 8 '17 at 8:25
answered May 2 '16 at 11:24
Stéphane ChazelasStéphane Chazelas
319k57604972
319k57604972
add a comment |
add a comment |
Try this simple example:
echo "$_"
echo "test"
echo "$_"
Run it by giving the absolute path (/home/$USERNAME/test.sh
); output:
/home/$USERNAME/test.sh
test
test
First $_
contains the path you used to invoke the script and the second one contains the first argument to the middle echo
.
For the third item in the list, if you start a new terminal and type echo $_
it will show the variable containing the PATH
which is usually used to lookup and invoke commands (in my Ubuntu machine) in a normal shell or absolute path to your .bashrs
file in a login shell.
For the item four from bash man page:
When used in the text of the message,
$_
expands to the name of the
current mailfile.
Thanks. (1) can you explain the third case with examples? (2) When I open a new gnome terminal tab, the output ofecho $_
isEDITOR
, and why is it? Which case does it follow? (3) Can you given an example of how to check mails, and of using$_
in this case?
– Tim
May 2 '16 at 0:00
Open your.bashrc
and comment out every line there. Keep only a single line containing a command likeecho "test"
or similar. Save and close. Then runbash
and immediatelyecho $_
. This last echo should print test in the output.
– coffeMug
May 2 '16 at 6:50
For the mail part I have not used Unix mail and don't have a working mail installed on my system now so cannot give you example. But should be obvious if you follow the description ofMAILPATH
in linuxcommand.org/lc3_man_pages/bash1.html
– coffeMug
May 2 '16 at 7:18
1
FYI, the canonical, up-to-date version of the bash manual is: gnu.org/software/bash/manual/bashref.html . It's version 4.3 while the linuxcommand page was 4.1.
– Jeff Schaller♦
May 2 '16 at 9:47
add a comment |
Try this simple example:
echo "$_"
echo "test"
echo "$_"
Run it by giving the absolute path (/home/$USERNAME/test.sh
); output:
/home/$USERNAME/test.sh
test
test
First $_
contains the path you used to invoke the script and the second one contains the first argument to the middle echo
.
For the third item in the list, if you start a new terminal and type echo $_
it will show the variable containing the PATH
which is usually used to lookup and invoke commands (in my Ubuntu machine) in a normal shell or absolute path to your .bashrs
file in a login shell.
For the item four from bash man page:
When used in the text of the message,
$_
expands to the name of the
current mailfile.
Thanks. (1) can you explain the third case with examples? (2) When I open a new gnome terminal tab, the output ofecho $_
isEDITOR
, and why is it? Which case does it follow? (3) Can you given an example of how to check mails, and of using$_
in this case?
– Tim
May 2 '16 at 0:00
Open your.bashrc
and comment out every line there. Keep only a single line containing a command likeecho "test"
or similar. Save and close. Then runbash
and immediatelyecho $_
. This last echo should print test in the output.
– coffeMug
May 2 '16 at 6:50
For the mail part I have not used Unix mail and don't have a working mail installed on my system now so cannot give you example. But should be obvious if you follow the description ofMAILPATH
in linuxcommand.org/lc3_man_pages/bash1.html
– coffeMug
May 2 '16 at 7:18
1
FYI, the canonical, up-to-date version of the bash manual is: gnu.org/software/bash/manual/bashref.html . It's version 4.3 while the linuxcommand page was 4.1.
– Jeff Schaller♦
May 2 '16 at 9:47
add a comment |
Try this simple example:
echo "$_"
echo "test"
echo "$_"
Run it by giving the absolute path (/home/$USERNAME/test.sh
); output:
/home/$USERNAME/test.sh
test
test
First $_
contains the path you used to invoke the script and the second one contains the first argument to the middle echo
.
For the third item in the list, if you start a new terminal and type echo $_
it will show the variable containing the PATH
which is usually used to lookup and invoke commands (in my Ubuntu machine) in a normal shell or absolute path to your .bashrs
file in a login shell.
For the item four from bash man page:
When used in the text of the message,
$_
expands to the name of the
current mailfile.
Try this simple example:
echo "$_"
echo "test"
echo "$_"
Run it by giving the absolute path (/home/$USERNAME/test.sh
); output:
/home/$USERNAME/test.sh
test
test
First $_
contains the path you used to invoke the script and the second one contains the first argument to the middle echo
.
For the third item in the list, if you start a new terminal and type echo $_
it will show the variable containing the PATH
which is usually used to lookup and invoke commands (in my Ubuntu machine) in a normal shell or absolute path to your .bashrs
file in a login shell.
For the item four from bash man page:
When used in the text of the message,
$_
expands to the name of the
current mailfile.
edited May 1 '16 at 22:31
answered May 1 '16 at 20:57
coffeMugcoffeMug
7,583112951
7,583112951
Thanks. (1) can you explain the third case with examples? (2) When I open a new gnome terminal tab, the output ofecho $_
isEDITOR
, and why is it? Which case does it follow? (3) Can you given an example of how to check mails, and of using$_
in this case?
– Tim
May 2 '16 at 0:00
Open your.bashrc
and comment out every line there. Keep only a single line containing a command likeecho "test"
or similar. Save and close. Then runbash
and immediatelyecho $_
. This last echo should print test in the output.
– coffeMug
May 2 '16 at 6:50
For the mail part I have not used Unix mail and don't have a working mail installed on my system now so cannot give you example. But should be obvious if you follow the description ofMAILPATH
in linuxcommand.org/lc3_man_pages/bash1.html
– coffeMug
May 2 '16 at 7:18
1
FYI, the canonical, up-to-date version of the bash manual is: gnu.org/software/bash/manual/bashref.html . It's version 4.3 while the linuxcommand page was 4.1.
– Jeff Schaller♦
May 2 '16 at 9:47
add a comment |
Thanks. (1) can you explain the third case with examples? (2) When I open a new gnome terminal tab, the output ofecho $_
isEDITOR
, and why is it? Which case does it follow? (3) Can you given an example of how to check mails, and of using$_
in this case?
– Tim
May 2 '16 at 0:00
Open your.bashrc
and comment out every line there. Keep only a single line containing a command likeecho "test"
or similar. Save and close. Then runbash
and immediatelyecho $_
. This last echo should print test in the output.
– coffeMug
May 2 '16 at 6:50
For the mail part I have not used Unix mail and don't have a working mail installed on my system now so cannot give you example. But should be obvious if you follow the description ofMAILPATH
in linuxcommand.org/lc3_man_pages/bash1.html
– coffeMug
May 2 '16 at 7:18
1
FYI, the canonical, up-to-date version of the bash manual is: gnu.org/software/bash/manual/bashref.html . It's version 4.3 while the linuxcommand page was 4.1.
– Jeff Schaller♦
May 2 '16 at 9:47
Thanks. (1) can you explain the third case with examples? (2) When I open a new gnome terminal tab, the output of
echo $_
is EDITOR
, and why is it? Which case does it follow? (3) Can you given an example of how to check mails, and of using $_
in this case?– Tim
May 2 '16 at 0:00
Thanks. (1) can you explain the third case with examples? (2) When I open a new gnome terminal tab, the output of
echo $_
is EDITOR
, and why is it? Which case does it follow? (3) Can you given an example of how to check mails, and of using $_
in this case?– Tim
May 2 '16 at 0:00
Open your
.bashrc
and comment out every line there. Keep only a single line containing a command like echo "test"
or similar. Save and close. Then run bash
and immediately echo $_
. This last echo should print test in the output.– coffeMug
May 2 '16 at 6:50
Open your
.bashrc
and comment out every line there. Keep only a single line containing a command like echo "test"
or similar. Save and close. Then run bash
and immediately echo $_
. This last echo should print test in the output.– coffeMug
May 2 '16 at 6:50
For the mail part I have not used Unix mail and don't have a working mail installed on my system now so cannot give you example. But should be obvious if you follow the description of
MAILPATH
in linuxcommand.org/lc3_man_pages/bash1.html– coffeMug
May 2 '16 at 7:18
For the mail part I have not used Unix mail and don't have a working mail installed on my system now so cannot give you example. But should be obvious if you follow the description of
MAILPATH
in linuxcommand.org/lc3_man_pages/bash1.html– coffeMug
May 2 '16 at 7:18
1
1
FYI, the canonical, up-to-date version of the bash manual is: gnu.org/software/bash/manual/bashref.html . It's version 4.3 while the linuxcommand page was 4.1.
– Jeff Schaller♦
May 2 '16 at 9:47
FYI, the canonical, up-to-date version of the bash manual is: gnu.org/software/bash/manual/bashref.html . It's version 4.3 while the linuxcommand page was 4.1.
– Jeff Schaller♦
May 2 '16 at 9:47
add a comment |
For case 2, an example is worth a thousand words:
mkdir my_long_dir
cd $_
Does what you'd guess / hope for. Gives me a simple placeholder when I'm on the command line to save me having to repeate myself.
add a comment |
For case 2, an example is worth a thousand words:
mkdir my_long_dir
cd $_
Does what you'd guess / hope for. Gives me a simple placeholder when I'm on the command line to save me having to repeate myself.
add a comment |
For case 2, an example is worth a thousand words:
mkdir my_long_dir
cd $_
Does what you'd guess / hope for. Gives me a simple placeholder when I'm on the command line to save me having to repeate myself.
For case 2, an example is worth a thousand words:
mkdir my_long_dir
cd $_
Does what you'd guess / hope for. Gives me a simple placeholder when I'm on the command line to save me having to repeate myself.
answered 14 mins ago
dszdsz
1693
1693
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f280453%2funderstand-the-meaning-of%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
-1 question unclear & not thoroughly researched. What have you tried? Where did your expectations misalign with the text? Do you not honestly understand the word 'subsequently'? If a new user were to ask this same question I would have the same questions of them (despite my similar innate curiosity as to exactly how things work).
– Jeff Schaller♦
May 2 '16 at 2:41