-ne——不等于(not equal) -lt——小于(less than) -le——小于等于(less equal) -gt——大于(great than) -ge——大于等于(great equal) -f——文件(file) -d——目录(directory) (一)选择执行语句 单分支的if语句 if 测试条件;then fi 双分支的if语句 if 测试条件;then 如果满足条件就执行这里的...
A -ne B: 不等于 not equal to 2.3 字符串测试:A, B A > B A < B A >= B A <= B A == B或A = B:等值比较 A != B: 不等于 -z A: 判断A是否为空;空则为真,不空则假; -n A:判断A是否不空;不空则为真,空则为假; =~ "$A" =~ PATTERN 如果变量A中保存的字符串能被PATTERN...
[ ARG1 OP ARG2 ] “OP” is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if “ARG1” is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to “ARG2”, respectively. “ARG1” and “AR...
/bin/bash#Device=/dev/sda3ifmount|grep"$Device"&>/dev/null;thengrep"$Device"|cut-d""-f3elseecho"$Deviceis not exist"fi 1. 2. 3. 4. 5. 6. 7. 8. 三、bash条件测试 1.整数测试 2.字符测试 3.文件测试 整数测试:数值1比较符号数值2 比较符号: -ge:相等(equal) -ne:不等(not equal...
if [[ $s1 = "abc" ]]; then echo "\$s1 is equal to \"abc\"" fi 上面的代码是判断字符串是否相等,如果相等,输出$s1 is equal to "abc",否则输出$s2 is not equal to "abc"。 n1=11 n2=10 3. 判断文件 上面的代码是判断文件是否存在、是否是常规文件和是否是目录。如果条件成立,则输出对应...
if [ "$string1" = "$string2" ]; then echo "The two strings are equal." else echo "The two strings are not equal." fi 这是我们执行脚本时的结果: 代码语言:txt 复制 $ ./test.sh The two strings are not equal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。
-ne 即-Not Equal的缩写,表示不等于 -o 即-or,表示前后二个逻辑判断是『或』的关系,类似的 -a 即-and,表示前后二个逻辑判断是『与』的关系 elif 即else if的缩写 上面的示例运行结果: 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 ...
n1 -ne n2 检查n1是否不等于n2 (not equal) $ if test 5 -eq 5;then echo "YES"; else echo "NO"; fi #两数相等YES $ if test 5 -ne 5;then echo "YES"; else echo "NO"; fi #两数不相等NO 字符串测试 命令描述 str1 = str2 检查str1是否和str2相同 str1 != str2 检查str1是否和...
$./test.shThetwostringsarenotequal. 例2 我们还可以使用运算符来测试两个字符串是否不相等!=。 #!/bin/bashstring1="apples"string2="oranges"if["$string1"!="$string2"];thenecho"Stringsaredifferent."elseecho"Stringsarenotdifferent."fi
[ ARG1 OP ARG2 ] “OP” is one of -eq, -ne, -lt, -le, -gt or -ge. These arithmetic binary operators return true if “ARG1” is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to “ARG2”, respectively. “ARG1” and “AR...