shell常用的判斷條件

來源:互聯網
上載者:User

標籤: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常用的判斷條件

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.