linux 中 while循环 ()与【】的区别

为什么中括号中可以用整数比较运算符不可意用"<="
小括号中可以用"<="不可意用整数比较运算符啊
中括号中用“<=”就出错;而小括号中用“<=”就没问题:
[root@localhost exam8]# cat hundred3.sh
#!/bin/bash
j=0
i=0
while [[ "$i" <= 102 ]]
do
let "j=j+i"
let "i=i+2"
done
echo "$j"
[root@localhost exam8]# vi hundred3.sh
[root@localhost exam8]# ./hundred3.sh
./hundred3.sh: line 4: syntax error in conditional expression
./hundred3.sh: line 4: syntax error near `102'
./hundred3.sh: line 4: `while [[ "$i" <= 102 ]]'
但是小括号中用“-lt”就不行 中括号中就没问题
[root@localhost exam8]# cat hundred3.sh
#!/bin/bash
j=0
i=0
while (( "$i" -lt 102 ))
do
let "j=j+i"
let "i=i+2"
done
echo "$j"
[root@localhost exam8]# ./hundred3.sh
./hundred3.sh: line 4: ((: 0 -lt 102 : syntax error in expression (error token is "102 ")
0
[root@localhost exam8]#

这个问题LZ不需要纠结吧,这就是Linux shell的语法特点啊!只能这样写,表达式才配套,才会正确。
温馨提示:答案为网友推荐,仅供参考
相似回答