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
bash command XOR ^ anothercommand
提问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 anothercommand
to 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 command
with two arguments, ^
and anothercommand
. There is no operator here. anothercommand
will only run if command
decides to treat that argument as a command name and attempt to run it.
如果您输入command ^ anothercommand
,您只是提供command
了两个参数,^
和anothercommand
。这里没有操作员。anothercommand
只有在command
决定将该参数视为命令名称并尝试运行它时才会运行。