{"id":183,"date":"2018-04-05T13:12:00","date_gmt":"2018-04-05T05:12:00","guid":{"rendered":"http:\/\/kkong.net\/?p=183"},"modified":"2018-04-05T13:22:58","modified_gmt":"2018-04-05T05:22:58","slug":"linux-shell%e7%bc%96%e7%a8%8b-if%e8%af%ad%e5%8f%a5-if-z-n-f-eq-ne-lt","status":"publish","type":"post","link":"https:\/\/kkong.net\/?p=183","title":{"rendered":"linux shell\u7f16\u7a0b\u2014\u2014if\u8bed\u53e5 if -z -n -f -eq -ne -lt"},"content":{"rendered":"<p>if  \u6761\u4ef6<br \/>\nthen<br \/>\n Command<br \/>\n Command<br \/>\nelse<br \/>\n Command<br \/>\n Command<br \/>\nfi                              \u522b\u5fd8\u4e86\u8fd9\u4e2a\u7ed3\u5c3e<br \/>\nIf\u8bed\u53e5\u5fd8\u4e86\u7ed3\u5c3efi<br \/>\ntest.sh: line 14: syntax error: unexpected end of fi<\/p>\n<p><strong>if \u7684\u4e09\u79cd\u6761\u4ef6\u8868\u8fbe\u5f0f<\/strong><br \/>\nif<br \/>\ncommand<br \/>\nthen<br \/>\nif<br \/>\n \u51fd\u6570<br \/>\nthen \t \u547d\u4ee4\u6267\u884c\u6210\u529f\uff0c\u7b49\u4e8e\u8fd4\u56de0 \uff08\u6bd4\u5982grep ,\u627e\u5230\u5339\u914d\uff09\u6267\u884c\u5931\u8d25\uff0c\u8fd4\u56de\u975e0 \uff08grep,\u6ca1\u627e\u5230\u5339\u914d\uff09<br \/>\nif [ expression_r_r_r  ]<br \/>\nthen  \t \u8868\u8fbe\u5f0f\u7ed3\u679c\u4e3a\u771f\uff0c\u5219\u8fd4\u56de0\uff0cif\u628a0\u503c\u5f15\u5411then<br \/>\nif test expression_r_r_r<br \/>\nthen \t \u8868\u8fbe\u5f0f\u7ed3\u679c\u4e3a\u5047\uff0c\u5219\u8fd4\u56de\u975e0\uff0cif\u628a\u975e0\u503c\u5f15\u5411then<br \/>\n\u4f20\u7edfif \u4ece\u53e5\u5b50\u2014\u2014\u4ee5\u6761\u4ef6\u8868\u8fbe\u5f0f\u4f5c\u4e3a if\u6761\u4ef6<\/p>\n<p>if<strong> [<\/strong><em> \u6761\u4ef6\u8868\u8fbe\u5f0f<\/em> <strong>]<\/strong><br \/>\nthen<br \/>\n command<br \/>\n command<br \/>\n command<br \/>\nelse<br \/>\n command<br \/>\n command<br \/>\nfi<\/p>\n<p>[ ] &&  \u2014\u2014\u5feb\u6377if<br \/>\n[ -f \"\/etc\/shadow\" ] && echo \"This computer uses shadow passwors\"<br \/>\n   && \u53ef\u4ee5\u7406\u89e3\u4e3athen\u5982\u679c\u5de6\u8fb9\u7684\u8868\u8fbe\u5f0f\u4e3a\u771f\u5219\u6267\u884c\u53f3\u8fb9\u7684\u8bed\u53e5 <\/p>\n<p>\u6587\u4ef6\u8868\u8fbe\u5f0f<br \/>\n-e filename \u5982\u679c filename\u5b58\u5728\uff0c\u5219\u4e3a\u771f<br \/>\n-d filename \u5982\u679c filename\u4e3a\u76ee\u5f55\uff0c\u5219\u4e3a\u771f<br \/>\n-f filename \u5982\u679c filename\u4e3a\u5e38\u89c4\u6587\u4ef6\uff0c\u5219\u4e3a\u771f<br \/>\n-L filename \u5982\u679c filename\u4e3a\u7b26\u53f7\u94fe\u63a5\uff0c\u5219\u4e3a\u771f<br \/>\n-r filename \u5982\u679c filename\u53ef\u8bfb\uff0c\u5219\u4e3a\u771f<br \/>\n-w filename \u5982\u679c filename\u53ef\u5199\uff0c\u5219\u4e3a\u771f<br \/>\n-x filename \u5982\u679c filename\u53ef\u6267\u884c\uff0c\u5219\u4e3a\u771f<br \/>\n-s filename \u5982\u679c\u6587\u4ef6\u957f\u5ea6\u4e0d\u4e3a0\uff0c\u5219\u4e3a\u771f<br \/>\n-h filename \u5982\u679c\u6587\u4ef6\u662f\u8f6f\u94fe\u63a5\uff0c\u5219\u4e3a\u771f<br \/>\nfilename1 -nt filename2 \u5982\u679c filename1\u6bd4 filename2\u65b0\uff0c\u5219\u4e3a\u771f\u3002<br \/>\nfilename1 -ot filename2 \u5982\u679c filename1\u6bd4 filename2\u65e7\uff0c\u5219\u4e3a\u771f\u3002<\/p>\n<p>\u6574\u6570\u53d8\u91cf\u8868\u8fbe\u5f0f<br \/>\n-eq \u7b49\u4e8e<br \/>\n-ne \u4e0d\u7b49\u4e8e<br \/>\n-gt \u5927\u4e8e<br \/>\n-ge \u5927\u4e8e\u7b49\u4e8e<br \/>\n-lt \u5c0f\u4e8e<br \/>\n-le \u5c0f\u4e8e\u7b49\u4e8e<\/p>\n<p>\u5b57\u7b26\u4e32\u53d8\u91cf\u8868\u8fbe\u5f0f<br \/>\nIf  [ $a = $b ]                 \u5982\u679cstring1\u7b49\u4e8estring2\uff0c\u5219\u4e3a\u771f<br \/>\n                                \u5b57\u7b26\u4e32\u5141\u8bb8\u4f7f\u7528\u8d4b\u503c\u53f7\u505a\u7b49\u53f7<br \/>\nif  [ $string1 !=  $string2 ]   \u5982\u679cstring1\u4e0d\u7b49\u4e8estring2\uff0c\u5219\u4e3a\u771f<br \/>\nif  [ -n $string  ]             \u5982\u679cstring \u975e\u7a7a(\u975e0\uff09\uff0c\u8fd4\u56de0(true)<br \/>\nif  [ -z $string  ]             \u5982\u679cstring \u4e3a\u7a7a\uff0c\u5219\u4e3a\u771f<br \/>\nif  [ $sting ]                  \u5982\u679cstring \u975e\u7a7a\uff0c\u8fd4\u56de0 (\u548c-n\u7c7b\u4f3c) <\/p>\n<p>    \u903b\u8f91\u975e !                   \u6761\u4ef6\u8868\u8fbe\u5f0f\u7684\u76f8\u53cd<br \/>\nif [ ! \u8868\u8fbe\u5f0f ]<br \/>\nif [ ! -d $num ]               \u5982\u679c\u4e0d\u5b58\u5728\u76ee\u5f55$num<br \/>\n    \u903b\u8f91\u4e0e \u2013a                   \u6761\u4ef6\u8868\u8fbe\u5f0f\u7684\u5e76\u5217<br \/>\nif [ \u8868\u8fbe\u5f0f1  \u2013a  \u8868\u8fbe\u5f0f2 ]<br \/>\n    \u903b\u8f91\u6216 -o                   \u6761\u4ef6\u8868\u8fbe\u5f0f\u7684\u6216<br \/>\nif [ \u8868\u8fbe\u5f0f1  \u2013o \u8868\u8fbe\u5f0f2 ]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>if \u6761\u4ef6 then Command Command else Command Command fi \u522b\u5fd8\u4e86\u8fd9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,5],"tags":[27,26],"_links":{"self":[{"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts\/183"}],"collection":[{"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=183"}],"version-history":[{"count":3,"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts\/183\/revisions"}],"predecessor-version":[{"id":186,"href":"https:\/\/kkong.net\/index.php?rest_route=\/wp\/v2\/posts\/183\/revisions\/186"}],"wp:attachment":[{"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=183"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=183"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kkong.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=183"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}