How can I recall the argument of the previous bash command?
!!:n
where n
is the 0-based position of the argument you want.
For example:
echo 'one' 'two'# "one two"echo !!:2# "two"
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!!
- previous command (often pronounced "bang bang")!n
- command numbern
fromhistory
!pattern
- most recent command matchingpattern
!!:s/find/replace
- last command, substitutefind
withreplace