{"id":210,"date":"2015-05-08T14:20:54","date_gmt":"2015-05-08T06:20:54","guid":{"rendered":"http:\/\/owemeawe.com\/?p=210"},"modified":"2016-09-04T11:19:53","modified_gmt":"2016-09-04T03:19:53","slug":"linux-shell%e8%84%9a%e6%9c%ac%e4%b9%8bif%e5%88%a4%e6%96%ad","status":"publish","type":"post","link":"https:\/\/peloo.net\/?p=210","title":{"rendered":"linux shell\u811a\u672c\u4e4bif\u5224\u65ad"},"content":{"rendered":"<p>\u65e0\u8bba\u4ec0\u4e48\u7f16\u7a0b\u8bed\u8a00\u90fd\u79bb\u4e0d\u5f00\u6761\u4ef6\u5224\u65ad\u3002SHELL\u4e5f\u4e0d\u4f8b\u5916\u3002<\/p>\n<p><strong>\u00a0\u00a0\u00a0\u00a0\u00a0 if list then<br \/>\ndo something here<br \/>\nelif list then<br \/>\ndo another thing here<br \/>\nelse<br \/>\ndo something else here<br \/>\nfi <\/strong><\/p>\n<p><strong>EX1:<\/strong><\/p>\n<p>#!\/bin\/sh<\/p>\n<p>SYSTEM=`uname -s`\u00a0\u00a0\u00a0 #\u83b7\u53d6\u64cd\u4f5c\u7cfb\u7edf\u7c7b\u578b\uff0c\u6211\u672c\u5730\u662flinux<\/p>\n<p>if [ $SYSTEM = \"Linux\" ] ; then\u00a0\u00a0\u00a0\u00a0 #\u5982\u679c\u662flinux\u7684\u8bdd\u6253\u5370linux\u5b57\u7b26\u4e32<br \/>\necho \"Linux\"<br \/>\nelif [ $SYSTEM = \"FreeBSD\" ] ; then<br \/>\necho \"FreeBSD\"<br \/>\nelif [ $SYSTEM = \"Solaris\" ] ; then<br \/>\necho \"Solaris\"<br \/>\nelse<br \/>\necho \"What?\"<br \/>\nfi\u00a0\u00a0\u00a0\u00a0 #ifend<\/p>\n<p>\u57fa\u672c\u4e0a\u548c\u5176\u4ed6\u811a\u672c\u8bed\u8a00\u4e00\u6837\u3002\u6ca1\u6709\u592a\u5927\u533a\u522b\u3002\u4e0d\u8fc7\u503c\u5f97\u6ce8\u610f\u7684\u662f\u3002[]\u91cc\u9762\u7684\u6761\u4ef6\u5224\u65ad\u3002<\/p>\n<p><strong>1 \u5b57\u7b26\u4e32\u5224\u65ad<\/strong><\/p>\n<p>str1 = str2\u3000\u3000\u3000\u3000\u3000\u3000\u5f53\u4e24\u4e2a\u4e32\u6709\u76f8\u540c\u5185\u5bb9\u3001\u957f\u5ea6\u65f6\u4e3a\u771f<br \/>\nstr1 != str2\u3000\u3000\u3000\u3000\u3000 \u5f53\u4e32str1\u548cstr2\u4e0d\u7b49\u65f6\u4e3a\u771f<br \/>\n-n str1\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u5f53\u4e32\u7684\u957f\u5ea6\u5927\u4e8e0\u65f6\u4e3a\u771f(\u4e32\u975e\u7a7a)<br \/>\n-z str1\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u5f53\u4e32\u7684\u957f\u5ea6\u4e3a0\u65f6\u4e3a\u771f(\u7a7a\u4e32)<br \/>\nstr1\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u00a0\u00a0 \u5f53\u4e32str1\u4e3a\u975e\u7a7a\u65f6\u4e3a\u771f<\/p>\n<p><strong>2 \u6570\u5b57\u7684\u5224\u65ad<\/strong><\/p>\n<p>int1 -eq int2\u3000\u3000\u3000\u3000\u4e24\u6570\u76f8\u7b49\u4e3a\u771f<br \/>\nint1 -ne int2\u3000\u3000\u3000\u3000\u4e24\u6570\u4e0d\u7b49\u4e3a\u771f<br \/>\nint1 -gt int2\u3000\u3000\u3000\u3000int1\u5927\u4e8eint2\u4e3a\u771f<br \/>\nint1 -ge int2\u3000\u3000\u3000\u3000int1\u5927\u4e8e\u7b49\u4e8eint2\u4e3a\u771f<br \/>\nint1 -lt int2\u3000\u3000\u3000\u3000int1\u5c0f\u4e8eint2\u4e3a\u771f<br \/>\nint1 -le int2\u3000\u3000\u3000\u3000int1\u5c0f\u4e8e\u7b49\u4e8eint2\u4e3a\u771f<\/p>\n<p><strong>2 \u6587\u4ef6\u7684\u5224\u65ad<\/strong><\/p>\n<p>-r \u6587\u4ef6\u6216\u76ee\u5f55\u5bf9\u6b64\uff08\u6709\u6548\u7684\uff09\u7528\u6237\uff08effective user\uff09\u6216\u7ec4\u662f\u53ef\u8bfb\u7684<br \/>\n-w \u6587\u4ef6\u6216\u76ee\u5f55\u5bf9\u6b64\uff08\u6709\u6548\u7684\uff09\u7528\u6237\u6216\u7ec4\u662f\u53ef\u5199\u7684<br \/>\n-x \u6587\u4ef6\u6216\u76ee\u5f55\u5bf9\u6b64\uff08\u6709\u6548\u7684\uff09\u7528\u6237\u6216\u7ec4\u662f\u53ef\u6267\u884c\u7684<br \/>\n-o \u6587\u4ef6\u6216\u76ee\u5f55\u7531\u672c\uff08\u6709\u6548\u7684\uff09\u7528\u6237\u6240\u6709<br \/>\n-R \u6587\u4ef6\u6216\u76ee\u5f55\u5bf9\u6b64\u7528\u6237(real user)\u6216\u7ec4\u662f\u53ef\u8bfb\u7684<br \/>\n-W \u6587\u4ef6\u6216\u76ee\u5f55\u5bf9\u6b64\u7528\u6237\u6216\u7ec4\u662f\u53ef\u5199\u7684<br \/>\n-X \u6587\u4ef6\u6216\u76ee\u5f55\u5bf9\u6b64\u7528\u6237\u6216\u7ec4\u662f\u53ef\u6267\u884c\u7684<br \/>\n-O \u6587\u4ef6\u6216\u76ee\u5f55\u7531\u672c\u7528\u6237\u6240\u6709<br \/>\n<strong><span style=\"color: #ff0000\">-e \u6587\u4ef6\u6216\u76ee\u5f55\u540d\u5b58\u5728<\/span><\/strong><br \/>\n-z \u6587\u4ef6\u5b58\u5728\uff0c\u5927\u5c0f\u4e3a0\uff08\u76ee\u5f55\u6052\u4e3afalse\uff09<br \/>\n<span style=\"color: #ff0000\"><strong>-s \u6587\u4ef6\u6216\u76ee\u5f55\u5b58\u5728\uff0c\u5927\u5c0f\u5927\u4e8e0\uff08\u503c\u4e3a\u6587\u4ef6\u7684\u5927\u5c0f\uff0c\u5355\u4f4d\uff1a\u5b57\u8282\uff09<\/strong><\/span><br \/>\n-f \u4e3a\u666e\u901a\u6587\u672c<br \/>\n-d \u4e3a\u76ee\u5f55<br \/>\n-l \u4e3a\u7b26\u53f7\u94fe\u63a5<br \/>\n-S \u4e3asocket<br \/>\n-p \u4e3a\u7ba1\u9053(Entry is a named pipe(a\u201cfifo\u201d))<br \/>\n-b \u4e3ablock-special \u6587\u4ef6\uff08\u5982\u6302\u8f7d\u78c1\u76d8\uff09<br \/>\n-c \u4e3acharacter-special \u6587\u4ef6\uff08\u5982I\/O \u8bbe\u5907\uff09<br \/>\n-u setuid \u7684\u6587\u4ef6\u6216\u76ee\u5f55<br \/>\n-g setgid \u7684\u6587\u4ef6\u6216\u76ee\u5f55<br \/>\n-k File or directory has the sticky bit set<br \/>\n-t \u6587\u4ef6\u53e5\u67c4\u4e3aTTY(\u7cfb\u7edf\u51fd\u6570isatty()\u7684\u8fd4\u56de\u7ed3\u679c\uff1b\u4e0d\u80fd\u5bf9\u6587\u4ef6\u540d\u4f7f\u7528\u8fd9\u4e2a\u6d4b\u8bd5)<br \/>\n-T \u6587\u4ef6\u6709\u4e9b\u50cf\u201c\u6587\u672c\u201d\u6587\u4ef6<br \/>\n-B \u6587\u4ef6\u6709\u4e9b\u50cf\u201c\u4e8c\u8fdb\u5236\u201d\u6587\u4ef6<br \/>\n-M \u4fee\u6539\u7684\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u5929\uff09<br \/>\n-A \u8bbf\u95ee\u7684\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u5929\uff09<br \/>\n-C \u7d22\u5f15\u8282\u70b9\u4fee\u6539\u65f6\u95f4\uff08\u5355\u4f4d\uff1a\u5929\uff09<\/p>\n<p><strong>3 \u590d\u6742\u903b\u8f91\u5224\u65ad<\/strong><\/p>\n<p>-a \u3000 \u3000\u3000\u3000\u3000\u3000 \u4e0e<br \/>\n-o\u3000\u3000\u3000\u3000\u3000\u3000\u3000 \u6216<br \/>\n!\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u3000\u975e<\/p>\n<p><strong>\u7ed3\u5c3e<\/strong><\/p>\n<p>\u8bed\u6cd5\u867d\u7136\u7b80\u5355\uff0c\u4f46\u662f\u5728SHELL\u91cc\u4f7f\u7528\u7684\u65f6\u5019\uff0c\u4ed6\u7684\u529f\u80fd\u53d8\u5f97\u5f3a\u5927\u4e86\u3002<\/p>\n<p>\u8f6c\u81ea:http:\/\/hi.baidu.com\/hlxcx\/blog\/item\/6a37bc0624e0f37c020881d9.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u65e0\u8bba\u4ec0\u4e48\u7f16\u7a0b\u8bed\u8a00\u90fd\u79bb\u4e0d\u5f00\u6761\u4ef6\u5224\u65ad\u3002SHELL\u4e5f\u4e0d\u4f8b\u5916\u3002 \u00a0\u00a0\u00a0\u00a0\u00a0 if list then do something here elif list then do another thing here else do something else here fi EX1: #!\/bin\/sh SYSTEM=`uname -s`\u00a0\u00a0\u00a0 #\u83b7\u53d6\u64cd\u4f5c\u7cfb\u7edf\u7c7b\u578b\uff0c\u6211\u672c\u5730\u662flinux if [ $SYSTEM = &#8220;Linux&#8221; ] ; then\u00a0\u00a0\u00a0\u00a0 #\u5982\u679c\u662flinux\u7684\u8bdd\u6253\u5370linux\u5b57\u7b26\u4e32 echo &#8220;Linux&#8221; elif [ $SYSTEM = &#8220;FreeBSD&#8221; ] ; then echo &#8220;FreeBSD&#8221; elif [ $SYSTEM = &#8220;Solaris&#8221; ] ; then&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/210"}],"collection":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=210"}],"version-history":[{"count":4,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/210\/revisions"}],"predecessor-version":[{"id":539,"href":"https:\/\/peloo.net\/index.php?rest_route=\/wp\/v2\/posts\/210\/revisions\/539"}],"wp:attachment":[{"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peloo.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}