①shell里的运算符 -a and -o or …
[root@instance-ehd67if1 local]# cat test.sh
#!/bin/bash
a=$1
if [ $1 -eq 1 -o $1 -eq 2 ];then
echo "yes"
else
echo "wrong"
fi
[root@instance-ehd67if1 local]# sh -x test.sh 1
+ a=1
+ '[' 1 -eq 1 -o 1 -eq 2 ']'
+ echo yes
yes
②[[ ]] 该符号可在shell里使用c语法,双括号里的语法为c语言,|| 为c语言的逻辑运算符,变量可不需双引号引起,shell内置关键字
[root@instance-ehd67if1 local]# cat test.sh
#!/bin/bash
a=$1
if [[ "$1" == "1" || "$1" == "2" ]];then
echo "yes"
else
echo "wrong"
fi
[root@instance-ehd67if1 local]# sh -x test.sh 1
+ a=1
+ [[ 1 == \1 ]]
+ echo yes
yes
③(( )) 其中一个作用同 [[ ]],另有整数扩展(计算表达式,exp)等
[root@instance-ehd67if1 local]# cat test.sh
#!/bin/bash
a=$1
if (( $1|0 ));then
echo "yes"
else
echo "wrong"
fi
[root@instance-ehd67if1 local]# sh -x test.sh 0
+ a=0
+ (( 0|0 ))
+ echo wrong
wrong
[root@instance-ehd67if1 local]# sh -x test.sh 1
+ a=1
+ (( 1|0 ))
+ echo yes
yes
详解引:
https://www.cnblogs.com/mianbaoshu/p/12069877.html
c运算符
算术运算符
关系运算符
逻辑运算符
位运算符
赋值运算符
杂项运算符
引:
https://www.runoob.com/cprogramming/c-operators.html
& 与 |或 ^ 非