Why start a shell command with a backslash?

BashShell

Bash Problem Overview


\curl -L https://get.rvm.io | bash -s stable

Why is the command starting with \? This is the site where I saw it.

Bash Solutions


Solution 1 - Bash

alias curl='curl --some --default --options'

If you have an alias for curl and you don't want to use it, putting a backslash in front disables the alias and runs the curl binary directly.

Note that this only applies at an interactive shell. Aliases don't take effect in scripts so it would be unnecessary there.

Solution 2 - Bash

The (Bourne/POSIX) shell specification says that alias substitution in an interactive shell is suppressed when any character of the command word is quoted. A backslash is one way to do that, but there are also other well known ways to quote: single and double quotes. All of the following will suppress alias substitution:

 \curl
 cur\l
 \c\u\r\l
 "c"url
 "curl"
 "c""u""r""l"
 'curl'
 'cu'"rl"

Using \curl is just the most common and readable way. Since this is a standardized feature, you can expect it to work in all Bourne-heritage shells.

\curl looks a bit like a TeX command, doesn't it? :-)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionlbabyView Question on Stackoverflow
Solution 1 - BashJohn KugelmanView Answer on Stackoverflow
Solution 2 - BashJensView Answer on Stackoverflow