Recall argument of previous command
!!:n where n is the 0-based position of the argument you want.
The ! prefix is used to access previous commands.
Other useful commands:
- !$ - last argument from previous command
- !^ - first argument (after the program/built-in/script) from previous command
- $_ - recall the last argument of the previous command.
- !! - previous command (often pronounced "bang bang")
- !n - command number n from history
- !pattern - most recent command matching pattern
- !!:s/find/replace - last command, substitute find with replace
Also, if you want an arbitrary argument, you can use !!:1, !!:2, etc. (!!:0 is the previous command itself.)
For example:
echo 'one' 'two'
# "one two"
echo !!:2
# "two"
If you know the number given in the history for a particular command, you can pretty much take any argument in that command using following terms.
Use following to take the second argument from the third command in the history,
!3:2
Use following to take the third argument from the fifth last command in the history,
!-5:3
Using a minus sign, you ask it to traverse from the last command of the history.
2019-05-13 17:35:15
Comments
Add a Comment