正确的选项是(增加推荐的顺序排列):
# Single POSIX test command with -o operator (not recommended anymore).
# Quotes strongly recommended to guard against empty or undefined variables.
while [ "$stats" -gt 300 -o "$stats" -eq 0 ]
# Two POSIX test commands joined in a list with ||.
# Quotes strongly recommended to guard against empty or undefined variables.
while [ "$stats" -gt 300 ] || [ "$stats" -eq 0 ]
# Two bash conditional expressions joined in a list with ||.
while [[ $stats -gt 300 ]] || [[ $stats -eq 0 ]]
# A single bash conditional expression with the || operator.
while [[ $stats -gt 300 || $stats -eq 0 ]]
# Two bash arithmetic expressions joined in a list with ||.
# $ optional, as a string can only be interpreted as a variable
while ((stats > 300)) || ((stats == 0))
# And finally, a single bash arithmetic expression with the || operator.
# $ optional, as a string can only be interpreted as a variable
while ((stats > 300 || stats == 0))
一些注意事项:
引用内部[[ ... ]]和((...))的参数扩展是可选的;如果变量没有设置,-gt和-eq将承担0.1
使用$里面((...))可选的值,但使用它可以帮助避免无意的错误。如果stats未设置,则((stats > 300))将假定为stats == 0,但(($stats > 300))将产生语法错误。