A trick to run shell examples with a leading $ (#snippet)

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….


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

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
$@

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

Thanks Remy and Mikkel!


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate
APA
Stefan Judis | Sciencx (2023-10-04T21:13:10+00:00) » A trick to run shell examples with a leading $ (#snippet). Retrieved from https://www.scien.cx/2020/12/07/a-trick-to-run-shell-examples-with-a-leading-snippet/.
MLA
" » A trick to run shell examples with a leading $ (#snippet)." Stefan Judis | Sciencx - Monday December 7, 2020, https://www.scien.cx/2020/12/07/a-trick-to-run-shell-examples-with-a-leading-snippet/
HARVARD
Stefan Judis | Sciencx Monday December 7, 2020 » A trick to run shell examples with a leading $ (#snippet)., viewed 2023-10-04T21:13:10+00:00,<https://www.scien.cx/2020/12/07/a-trick-to-run-shell-examples-with-a-leading-snippet/>
VANCOUVER
Stefan Judis | Sciencx - » A trick to run shell examples with a leading $ (#snippet). [Internet]. [Accessed 2023-10-04T21:13:10+00:00]. Available from: https://www.scien.cx/2020/12/07/a-trick-to-run-shell-examples-with-a-leading-snippet/
CHICAGO
" » A trick to run shell examples with a leading $ (#snippet)." Stefan Judis | Sciencx - Accessed 2023-10-04T21:13:10+00:00. https://www.scien.cx/2020/12/07/a-trick-to-run-shell-examples-with-a-leading-snippet/
IEEE
" » A trick to run shell examples with a leading $ (#snippet)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2020/12/07/a-trick-to-run-shell-examples-with-a-leading-snippet/. [Accessed: 2023-10-04T21:13:10+00:00]
rf:citation
» A trick to run shell examples with a leading $ (#snippet) | Stefan Judis | Sciencx | https://www.scien.cx/2020/12/07/a-trick-to-run-shell-examples-with-a-leading-snippet/ | 2023-10-04T21:13:10+00:00
https://github.com/addpipe/simple-recorderjs-demo