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

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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

6 Comments

Aliases can be used in scripts by using shopt -s expand_aliases before use of the alias
@lbaby Same in Kornshell. You dealias a possible command alias by putting a backslash in front of it. This is very common in Kornshell when people define command prompts with the name of the directory in them. Note the first line of this function is ` \cd "$@"`.
It's worth noting that \curl doesn't bypass any shell function named curl. For that, you can use the bash built-in command command: command curl ...
A easier-to-understand way to write \curl ... is command curl ...
Note that dash (and possibly other shells, although you're correct for bash without expand_aliases) does expand aliases in scripts.
|
194

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? :-)

7 Comments

+1 for giving the specific reason why \curl bypasses an aliases of the same name; note that only aliases are bypassed this way, not shell functions; command curl ... would ensure bypassing either.
I don't see the point of the last sentence. By the way, you only mention bypassing aliases, but any kind of quoting will also bypass keywords.
@mklement0 Not quite ensure… command() { echo "Not command, lol!"; } ; command -V echo ; \command -V echo ; \command command echo "This is command! (masking despair)" prints Not command, lol! x 3.
@AdrianGünter: Yes, if you replace command itself with a shell function, you're defeating the mechanism. What your example shows is that \ doesn't bypass functions, as stated. A non-self-defeating example: date() { echo 'not date'; }; date; command date. If you're worried about malicious tampering with command, see stackoverflow.com/a/35931876/45375
@mklement0 I understand all that, but my point is that if one can't guarantee that any other command name doesn't exist as a function (i.e., you lack control over your execution environment), then one also can't rely on command to not be overridden. From your own link: Thus, with no control over the execution environment, you cannot write shell scripts that are fully immune to tampering, unless you know that your code will be executed by dash, ksh, or bash (with the workaround in place)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.