---

Bash !$ Trick: Insert the Last Argument of the Previous Command

This shortcut allows you to recall and reuse the last argument from the previous command without having to retype it. Especially when dealing with lengthy file paths or complex commands, !$ can save time and reduce the chance of errors. In this guide, we’ll explore how it works, look at examples, and compare it with related tools like $_ and the Alt + . keyboard shortcut.

If you’re just starting to explore shell scripting, it might be useful to first read this beginner-friendly guide to echo in shell scripting.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis