Published at
Updated at
Reading time
1min

Remy Sharp shared a beautiful shell trick that he found in Mikkel Malmberg's dotfiles. You probably know the inconvenience (it's not a big problem in my opinion); you read some documentation and find a shell command you have to run. Unfortunately, it includes a leading $ symbol. Now, you have to carefully copy the line to exclude the $ because your shell won't understand the $.

What if your shell would be able to deal with a leading $ in your pasted commands? Here's the solution.

Add a $ file to your $PATH that includes the following and you're done! 🎉

#!/bin/zsh
exec "$@"

All the $ command does is running the rest of the passed command arguments. That's beautiful!

Thanks Remy and Mikkel!

If you enjoyed this article...

Join 5.5k readers and learn something new every week with Web Weekly.

Web Weekly — Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles