差异猛砸IF之间用括号和方括号声明 [英] Difference in Bash between IF statements with parenthesis and square brackets
问题描述
虽然学习一些关于庆典,我来看看四种类型的用的工作方式,如果
语句:
While learning a bit about bash, I come to see four types of ways of working with if
statements:
- 单括号 - (...)
- 双括号 - ((...))
- 单括号 - [...]
- 双方括号 - [[...]]
是什么在bash括号和方括号之间的区别。
What is the difference between Parenthesis and Square Brackets in bash.
推荐答案
您已经列出的测试:
- 单括号 - (...)正在创建一个子shell
- 双括号 - ((...))是算术运算
- 单括号 - [...]是语法POSIX
测试
- 双方括号 - [[...]]是bash的条件前pressions的语法(类似
测试
但功能更强大)
- Single Parenthesis - ( ... ) is creating a subshell
- Double Parenthesis - (( ... )) is for arithmetic operation
- Single Square Bracket - [ ... ] is the syntax for the POSIX
test
- Double Square Brackets - [[ ... ]] is the syntax for bash conditional expressions (similar to
test
but more powerful)
并不详尽,您可以使用的布尔逻辑的
are not exhaustive, you can use boolean logic
if command; then ...
太,因为这些命令都退出状态。在庆典
, 0
是真正
和> 0
是假
。
您可以看到这样的退出状态:
You can see the exit status like this :
command
echo $?
请参阅:
<一个href=\"http://wiki.bash-hackers.org/syntax/basicgrammar\">http://wiki.bash-hackers.org/syntax/basicgrammar
<一href=\"http://wiki.bash-hackers.org/syntax/arith_expr\">http://wiki.bash-hackers.org/syntax/arith_expr
<一href=\"http://mywiki.wooledge.org/BashGuide/TestsAndConditionals\">http://mywiki.wooledge.org/BashGuide/TestsAndConditionals
这篇关于差异猛砸IF之间用括号和方括号声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!