-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 测试条
string2="oranges" if [ "$string1" = "$string2" ]; then echo "The two strings are equal." else echo "The two strings are not equal." fi 这是我们执行脚本时的结果: 代码语言:txt AI代码解释 $ ./test.sh The two strings are not equal. 例2 我们还可以使用运算符来测试两个字符串是否...
-eq(equal) 检测两个数是否相等,相等则返回 true -ne(not equal) 检测两个数是否相等,不相等则返回 true -gt(greater than) 检测左边的数是否大于右边的,如果是,则返回 true -lt(lower than) 检测左边的数是否小于右边的,如果是,则返回 true -ge(greater equal) 检测左边的数是否大于等于右边的,如果是,则...
if [ "$str1" != "$str2" ]; then echo "Strings are not equal" else echo "Strings are equal" fi 字符串为空比较:可以使用双等号(==)来比较一个字符串是否为空。例如: 代码语言:txt 复制 str="" if [ "$str" == "" ]; then echo "String is empty" else echo "String is not empty"...
-eq 相等(equal) -ne 不等(not equal) -gt 大于(greater than) -lt 小于(less than) -ge 大于等于 (greater than or equal) -le 小于等于 (less than or equal) eg:if [ $max -gt $min ] 字符串的比较: [ $str1 = $str2 ] 等于 ...
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...
n1 -le n2 检查n1是否小于或等于n2 (less and equal) n1 -lt n2 检查n1是否小于n2 (less than) 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 #两数不...
[ 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...
TestFile1 does not exist or is empty. 现在创建一个空文件用来测试: [student@studentvm1 testdir]$ File="TestFile1" ; touch $File ; if [ -s $File ] ; then echo "$File exists and contains data." ; else echo "$File does not exist or is empty." ; fi ...
if [[ $USER = 'username' ]]; then echo "true" else echo "false" fi 1. 2. 3. 4. 5. not equal:!= numeric equality:-eq not equals:-ne is empty:-z if [[ 1 -eq 1 ]]; if [[ -z $USER ]]; 1. 2. 3. Elif if [[ -z $USER ]]; then ...