shell

Reusing Arguments with Bash Command `!$` is Quite Convenient

I'm introducing Bash's `!$` which can reuse arguments and is quite convenient. A typical example would be doing cd after mkdir. It can also be used for things like doing <code>docker rm</code> after <code>docker kill</code>…

Shou Arisaka
1 min read
Oct 6, 2025

I’m introducing Bash’s !$ which can reuse arguments and is quite convenient.

A typical example would be doing cd after mkdir. It can also be used for things like doing docker rm after docker kill… or maybe not.

$ mkdir -p hoge/fuga
$ cd !$
cd hoge/fuga
/hoge/fuga$ echo !$
echo hoge/fuga
hoge/fuga

# If there are 2 or more arguments, it will be the last one
/hoge/fuga$ mkdir -p hgoe/fuga foo/bar/baz
/hoge/fuga$ echo !$
echo foo/bar/baz
foo/bar/baz

Share this article

Shou Arisaka Oct 6, 2025

🔗 Copy Links