標籤:style blog color ar sp 檔案 資料 div on
1、判斷檔案夾是否存在if [ -d /home/q/www ];then echo "true"; else echo "false" ;fi(系統記憶體在檔案夾 /home/q/www)2、判斷檔案是否存在if [ -e /etc/passwd ];then echo "true"; else echo "false" ;fiif [ -f /etc/passwd ];then echo "true"; else echo "false" ;fi檔案存在且大小大於0if [ -s /etc/passwd ];then echo "true"; else echo "false" ;fi3、判斷檔案可讀if [ -r /etc/passwd ];then echo "true"; else echo "false" ;fi4、判斷檔案可寫if [ -w /etc/passwd ];then echo "true"; else echo "false" ;fi5、判斷檔案可執行if [ -x /etc/passwd ];then echo "true"; else echo "false" ;fi6、字串長度為0,返回真長度為0if [ -z "" ];then echo "true"; else echo "false" ;fi長度不為0if [ -z "xiaoqiang" ];then echo "true"; else echo "false" ;fi7、字串長度不為0,返回真長度不為0if [ -n "xiaoqiang" ];then echo "true"; else echo "false" ;fi長度為0if [ -n "" ];then echo "true"; else echo "false" ;fi8、判斷字串相等if [ "xiaoqiang" = "xiaoqiang" ];then echo "true"; else echo "false" ;fi9、判斷字串不相等if [ "xiaoqiang" != "xiaoqiang" ];then echo "true"; else echo "false" ;fi10、判斷整數相等if [ 1 -eq 1 ];then echo "true"; else echo "false" ;fi11、判斷整數不相等if [ 1 -ne 1 ];then echo "true"; else echo "false" ;fi12、判斷整數 1 < 2if [ 1 -lt 2 ];then echo "true"; else echo "false" ;fi13、判斷整數 2 <= 2if [ 2 -le 2 ];then echo "true"; else echo "false" ;fi14、判斷整數3 > 2if [ 3 -gt 2 ];then echo "true"; else echo "false" ;fi15、判斷整數 3 >= 3if [ 3 -ge 3 ];then echo "true"; else echo "false" ;fi16、邏輯運算!(非)if [ ! 3 -ge 3 ];then echo "true"; else echo "false" ;fi-a(and) if [ -z "" -a 3 -ge 3 ];then echo "true"; else echo "false" ;fi -o(或)if [ -z "sadfsa" -o 3 -ge 3 ];then echo "true"; else echo "false" ;fi17、特殊變數echo "number:$#" 擷取參數個數echo "scname:$0" 擷取指令碼名稱echo "first:$1" 擷取第一個參數echo "second:$2" 擷取第二個參數echo "argume:[email protected]" 擷取所有參數echo "show parm list :$*" 資料參數的listecho "show process id :$$" 擷取進程idecho "show precomm stat:$?" 擷取命令執行的結果
shell常用的判斷條件