43

looking at the magic installers which appear for all types of projects (e.g. for rvm) you'll always see commands like:

\curl ... | bash

e.g.

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

And I was wondering why these commands start with a slash - they seem to run fine without it.

Any suggestions?

fedorqui
  • 275,237
  • 103
  • 548
  • 598
pagid
  • 13,559
  • 11
  • 78
  • 104

3 Answers3

66

This is used to call the "original" command, avoiding it to be called with the possible aliases. That is, disables the possible aliases on the command curl and adjusts to the original one.

If you have

alias grep='grep --color=auto'

and then you do grep, it will have colours. So if you do not want colours, you would just write \grep.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
  • 7
    Thanks ... simple when you know it but impossible to find via Google ;) – pagid Apr 11 '13 at 16:08
  • 3
    it will call the original command ONLY if there is no function with the same name. Please see my answer for the alias/function/command order of evaluation by bash (In a nutshell: `\something` : will only avoid the alias, but will not bypass a function. `command something` : will bypass the alias AND the function and launch the command "something") – Olivier Dulac Apr 18 '13 at 12:38
  • This is an interesting point, @OlivierDulac. I found quite several options in a related post: http://stackoverflow.com/q/6162903/1983854 . Following your example, yes, `\something` just bypasses the alias, not the possible functions with this name. To do so, `$(which command)`, `"command"`, can work. – fedorqui Apr 20 '13 at 11:23
  • @fedorqui: or the (bash internal) `command` keyword can too. As in : `command thecommand`. See my answer ^^ – Olivier Dulac Jul 22 '13 at 11:39
  • @pagid I actually found this using Google: why "\curl" – Stephen Dec 30 '17 at 21:27
24

it's a backslash

it is to start the command starting with that name (OR the function) but not the ALIAS.

To make sure to bypass both function AND alias :

command somecommand

To bypass just the alias (and thus launch a function, or if no function, the command):

\somecommand

Let's see which takes precedence over which (I use bash 2.05b ... ymmv)

I'll define a function AND an alias with the same name as a command (ls) :

$ alias ls='echo A'
$ function ls { echo B ; }

Using "type -all ls" shows the order of evaluation :

$ type -all ls
ls is aliased to `echo A'
ls is a function
ls ()
{
    echo B
}
ls is /usr/bin/ls

But we can find out also by trying them out:

$ ls
A
$ \ls
B
$ command ls
file1 file2 file3

So it seems the order of precedence is : alias -before- function -before- command taken in the path. This is the order in bash (and the command command too.) - I noticed it differs in some other shells!

Of course, if you precise the relative/absolute path, it is then forced to be the command pointed at:

$ /usr/bin/ls
file1 file2 file3
Cadoiz
  • 1,446
  • 21
  • 31
Olivier Dulac
  • 3,695
  • 16
  • 31
3

It bypasses a possible alias curl.

Adrian Frühwirth
  • 42,970
  • 10
  • 60
  • 71