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

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

Jens
  • 69,818
  • 15
  • 125
  • 179
lbaby
  • 2,488
  • 2
  • 16
  • 12

2 Answers2

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

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • 5
    Aliases can be used in scripts by using `shopt -s expand_aliases` before use of the alias – Alex Mar 28 '13 at 21:06
  • @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](http://stackoverflow.com/a/8468165/368630). Note the first line of this function is ` \cd "$@"`. – David W. Mar 28 '13 at 21:33
  • 3
    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 ...` – Keith Thompson Mar 28 '13 at 21:55
  • 8
    A easier-to-understand way to write `\curl ...` is `command curl ...` – glenn jackman Mar 28 '13 at 21:55
  • Note that `dash` (and possibly other shells, although you're correct for `bash` without `expand_aliases`) *does* expand aliases in scripts. – Adrian Günter Apr 12 '18 at 19:49
  • I see backslashed commands in shell scripts that are meant to be sourced – Kevin Olree Apr 10 '19 at 15:02
182

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

Jens
  • 69,818
  • 15
  • 125
  • 179
  • 25
    +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_. – mklement0 Apr 21 '14 at 21:30
  • 1
    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._ – gniourf_gniourf Dec 27 '16 at 11:58
  • 1
    @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. – Adrian Günter Apr 12 '18 at 02:53
  • 4
    @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 https://stackoverflow.com/a/35931876/45375 – mklement0 Apr 12 '18 at 03:56
  • 2
    @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)` – Adrian Günter Apr 12 '18 at 17:54
  • 1
    `\curl` works like a charm. I had been using `/usr/bin/curl` to bypass an alias. Thanks for saving me 8 keystrokes! – exbctel Sep 20 '19 at 18:56
  • `\CurLTeX` is a version of TeX where TeX statements are evaluated by sliding them across an icy network and altering the upcoming network nodes settings before statement arrival via special broom-based editing in order to change the network path....resulting in gorgeous rendering of mathematical equations. – xdhmoore Apr 14 '21 at 05:36