Bash Bash history substitutions Using !$


Example

You can use the !$ to reduce repetition when using the command line:

$ echo ping
ping
$ echo !$
ping

You can also build upon the repetition

$ echo !$ pong
ping pong
$ echo !$, a great game
pong, a great game

Notice that in the last example we did not get ping pong, a great game because the last argument passed to the previous command was pong, we can avoid issue like this by adding quotes. Continuing with the example, our last argument was game:

$ echo "it is !$ time"
it is game time
$ echo "hooray, !$!"
hooray, it is game time!