当前位置: 首页 > 工具软件 > program-o > 使用案例 >

script bash 中 [[ ]] 与[ ] ,&& 与 -a,|| 与 -o的使用与区别

周浩博
2023-12-01

例子:这两个例子的执行结果是一样的

用[[ ]] 与 &&

#!/bin/bash
#Program:
#       Use loop
#History:
#       2013/10/31 first release

while [[ "$yn" != "yes" && "$yn" != "YES" ]]

do
        read -p "Please input yes/YES to confirm:" yn
done
echo "Ok! you type write, congratulations!!"

用[ ] 与 -a

#!/bin/bash
#Program:
#       Use loop
#History:
#       2013/10/31 first release

while [ "$yn" != "yes" -a "$yn" != "YES" ]

do
        read -p "Please input yes/YES to confirm:" yn
done
echo "Ok! you type write, congratulations!!"

|| 和-o 同上

 

 类似资料: