Tip: A bash alias for copying from the web

Git, Configuration · Mar 5, 2023

If you've ever copied a terminal command from the web, chances are you've also copied the dollar sign ($) that precedes it. This is a small annoyance that many developers encounter almost daily, but it can be easily dealt with. All you need to do is add an alias for the dollar sign to your .bashrc or .zshrc file:

alias '$'=''

But what about variables? Aren't these prefixed with a dollar sign? This alias won't break your scripts, as aliases replace only the first word of each simple command. Simply put, the only dollar sign that will be replaced is the one at the beginning of the line.

Written by Angelos Chalaris

I'm Angelos Chalaris, a JavaScript software engineer, based in Athens, Greece. The best snippets from my coding adventures are published here to help others learn to code.

If you want to keep in touch, follow me on GitHub or Twitter.

More like this