bash 命令 XOR ^ anothercommand

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42505552/
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 15:49:47  来源:igfitidea点击:

bash command XOR ^ anothercommand

linuxbashoperatorsdelimiterlogical-operators

提问by AK_

In the example below:

在下面的例子中:

w ^ ls

what's the expected behaviour of the XOR operator in shell?

shell 中 XOR 运算符的预期行为是什么?

So when we enter

所以当我们进入

command ^ anothercommand

what triggers anothercommandto run (if it will execute at all)?

什么触发器anothercommand运行(如果它会执行)?

回答by choroba

As you can see in man bash, ^is not used to separate commands, it's used inside arithmetic expressions.

正如您在 中所见,man bash,^不用于分隔命令,它用于算术表达式中。

$ echo $(( 5 ^ 9 ))
12

That's because

那是因为

dec     bin
 5     0101
 9     1001
-----------
12     1100

回答by chepner

If you enter command ^ anothercommand, you are simply providing commandwith two arguments, ^and anothercommand. There is no operator here. anothercommandwill only run if commanddecides to treat that argument as a command name and attempt to run it.

如果您输入command ^ anothercommand,您只是提供command了两个参数,^anothercommand。这里没有操作员。anothercommand只有在command决定将该参数视为命令名称并尝试运行它时才会运行。