#!/bin/sh #测试各种字符串比较操作. #shell中对变量的值添加单引号, the difference between the hot quotes and the not added: it is irrelevant to the type, that is, not adding quotes into the string type, #单引号不对相关量进行替换, if the $ symbol is not interpreted as a variable reference, thus substituting for the value of the corresponding variable, double quotes will be substituted Author:tenfyguo a= "$ b=" $ "$ echo" entered the original value: A= $A, b= $B "#判断字符串是否相等 if [" $A "=" $B "];then echo" [=] "fi #判断字符串是否相等, with on face = equivalent if ["$A" = = "$B"];then echo "[=]" fi #注意: the function of = = is different in [[]] and [], as follows #如果 $a with "A" (pattern match) then will be true if [[$A] = * ]];then echo "[[==a*]]" fi #如果 $a equals a * (character match), the result is true if [["$A" = = "*"]];then echo "==/" a*/"" Fi #File globbing "(wildcard
And word splitting will occur, and a * will automatically match to the corresponding file currently beginning with a: add_crontab.sh, the following will output OK #if ["add_crontab.sh" = = *];then #echo "OK" #fi if ["$A" = *];then echo "[==a*]" fi #如果 $a equals a * (character match), then the result is true if ["$A" = "*"];then echo "==/" * /"" "Fi #字符串不相等 If [" $A "!=" $B "];then echo" [!=] "fi #字符串不相等 if [[$A]"!= "$B"]];then echo "[[!=]]" fi #字符串不为空,
Length is not 0 if [-N "$A"];then echo "[-n]" fi #字符串为空. That's the length of 0. If [-Z "$A"];then echo "[-z]" fi #需要转义, otherwise it is considered a redirection symbol if [$A/<$B];then echo "[<]" fi if [$A < $B]];then echo [[[<]] "fi #需要转义", otherwise considered to be a redirection symbol if [$A/> $B]
Then echo "[>]" fi if [[$A > $B]];then echo [[>]] "fi