Powered by Typecho)))
Optimized by EAimTY
在写Shell脚本的时候,经常在写条件判断语句时不知道该用
[]
还是
[[]]
,首先我们来看他们的类别:
$type [ [[ test
[ is a shell builtin
[[ is a shell keyword
test is a shell builtin
[
和
test
是 Shell 的内部命令,而
[[
是Shell的关键字。
$test -f settings.py && echo True
True
$[ -f settings.py ] && echo True
True
[ 和test 是相等的。
$[ 2 < 1 ] && echo True || echo False
True
$[[ 2 < 1 ]] && echo True || echo False
False