$_ vs !$. Last argument of the preceding command and output redirection
72
votes
2
answers
45307
views
The question is about special variables. Documentation says:
>
!!:$
>
> designates the **last argument of the preceding command**. This may
> be shortened to !$
.
----
> ($_
, an underscore.) 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.
There must be some difference I cannot catch, because:
$ echo "hello" > /tmp/a.txt
$ echo "!$"
echo "/tmp/a.txt"
/tmp/a.txt
$ echo "hello" > /tmp/a.txt
$ echo $_
hello
What is the difference?
Asked by Loom
(4073 rep)
Mar 23, 2016, 10:49 AM
Last activity: May 27, 2022, 12:51 PM
Last activity: May 27, 2022, 12:51 PM