\卷曲... | bash ... 什么是斜线?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15951772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 05:10:24  来源:igfitidea点击:

\curl ... | bash ... what's the slash for?

bashshell

提问by pagid

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

查看为所有类型的项目(例如 rvm)出现的魔术安装程序,您将始终看到如下命令:

\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?

有什么建议?

回答by fedorqui 'SO stop harming'

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 curland adjusts to the original one.

这用于调用“原始”命令,避免使用可能的别名调用它。也就是说,禁用命令上可能的别名curl并调整为原始别名。

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.

然后你这样做grep,它会有颜色。因此,如果您不想要颜色,则只需编写\grep.

回答by Olivier Dulac

it's a backslash

这是一个反斜杠

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

它是启动以该名称(或函数)而不是 ALIAS 开头的命令。

To make sure to bypass both functionAND alias:

要确保绕过functionalias

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)

让我们看看哪个优先于哪个(我使用 bash 2.05b ... ymmv)

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

我将定义一个函数和一个与命令 (ls) 同名的别名:

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

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

使用“type -all ls”显示评估顺序:

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

所以看起来优先顺序是:alias-before- function-before- commandtake in the path

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

回答by Adrian Frühwirth

It bypasses a possible alias curl.

它绕过了一个可能的别名curl