- 論壇徽章:
- 0
|
[] 是 test 命令的 builtin 擴(kuò)展,為了效率。
With version 2.02, Bash introduced the [[ ... ]] extended test command, which performs comparisons in a manner more familiar to programmers from other languages. Note that [[ is a keyword, not a command.Bash sees [[ $a -lt $b ]] as a single element, which returns an exit status.
------ Advanced Bash Shell Scripting Guide
所以: [[]] 里面的and 和or 就可以寫(xiě)成 [[ -f file1 && -e file2 || -S file3 ]]
用 [] 的話, 需要寫(xiě)成 [ -f file1 -a -e file2 -o -S file3]
優(yōu)先用[[]] 可以避免 一些錯(cuò)誤。 |
|