Re-call Command Line Arguments in BASH
BASH
's history expansion character, !
has many features, including !:
for choosing a specific argument (or range of arguments) from the history. The gist is any number after !:
is the number of the argument you want, with !:1
being the first argument and !:0
being the command.
echo one two three
one two three
echo !:2
echo two
two
echo !:1 !:0
echo two echo
two echo
You can also re-run the last command in its entirety:
ls /root/.ssh
ls: cannot access /root/.ssh: Permission denied
# let's rerun that, but elevate privileges
sudo !!
sudo ls /root/.ssh
config
Cool.