{"id":162202,"date":"2019-11-24T09:00:39","date_gmt":"2019-11-24T01:00:39","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=162202"},"modified":"2019-10-24T09:57:21","modified_gmt":"2019-10-24T01:57:21","slug":"shell-flow-control","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/shell-flow-control.html","title":{"rendered":"Shell \u6d41\u7a0b\u63a7\u5236"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u548cJava\u3001PHP\u7b49\u8bed\u8a00\u4e0d\u4e00\u6837\uff0csh\u7684\u6d41\u7a0b\u63a7\u5236\u4e0d\u53ef\u4e3a\u7a7a.<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"
\n\u5982(\u4ee5\u4e0b\u4e3aPHP\u6d41\u7a0b\u63a7\u5236\u5199\u6cd5)\uff1a<\/p>\n

< ?php\r\nif (isset($_GET[\"q\"])) {\r\n    search(q);\r\n}\r\nelse {\r\n    \/\/ \u4e0d\u505a\u4efb\u4f55\u4e8b\u60c5\r\n}<\/pre>\n

\u5728sh\/bash\u91cc\u53ef\u4e0d\u80fd\u8fd9\u4e48\u5199\uff0c\u5982\u679celse\u5206\u652f\u6ca1\u6709\u8bed\u53e5\u6267\u884c\uff0c\u5c31\u4e0d\u8981\u5199\u8fd9\u4e2aelse\u3002<\/p>\n

if else<\/strong><\/p>\n

if<\/strong>
\nif \u8bed\u53e5\u8bed\u6cd5\u683c\u5f0f\uff1a<\/p>\n

if condition\r\nthen\r\n    command1 \r\n    command2\r\n    ...\r\n    commandN \r\nfi<\/pre>\n

\u5199\u6210\u4e00\u884c\uff08\u9002\u7528\u4e8e\u7ec8\u7aef\u547d\u4ee4\u63d0\u793a\u7b26\uff09\uff1a<\/p>\n

if [ $(ps -ef | grep -c \"ssh\") -gt 1 ]; then echo \"true\"; fi<\/pre>\n

\u672b\u5c3e\u7684fi\u5c31\u662fif\u5012\u8fc7\u6765\u62fc\u5199\uff0c\u540e\u9762\u8fd8\u4f1a\u9047\u5230\u7c7b\u4f3c\u7684\u3002<\/p>\n

if else<\/strong><\/p>\n

if else \u8bed\u6cd5\u683c\u5f0f\uff1a<\/p>\n

if condition\r\nthen\r\n    command1 \r\n    command2\r\n    ...\r\n    commandN\r\nelse\r\n    command\r\nfi<\/pre>\n

if else-if else<\/strong><\/p>\n

if else-if else \u8bed\u6cd5\u683c\u5f0f\uff1a<\/p>\n

if condition1\r\nthen\r\n    command1\r\nelif condition2 \r\nthen \r\n    command2\r\nelse\r\n    commandN\r\nfi<\/pre>\n

\u4ee5\u4e0b\u5b9e\u4f8b\u5224\u65ad\u4e24\u4e2a\u53d8\u91cf\u662f\u5426\u76f8\u7b49\uff1a<\/p>\n

a=10\r\nb=20\r\nif [ $a == $b ]\r\nthen\r\n   echo \"a \u7b49\u4e8e b\"\r\nelif [ $a -gt $b ]\r\nthen\r\n   echo \"a \u5927\u4e8e b\"\r\nelif [ $a -lt $b ]\r\nthen\r\n   echo \"a \u5c0f\u4e8e b\"\r\nelse\r\n   echo \"\u6ca1\u6709\u7b26\u5408\u7684\u6761\u4ef6\"\r\nfi<\/pre>\n

\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n

a \u5c0f\u4e8e b<\/pre>\n

if else\u8bed\u53e5\u7ecf\u5e38\u4e0etest\u547d\u4ee4\u7ed3\u5408\u4f7f\u7528\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

num1=$[2*3]\r\nnum2=$[1+5]\r\nif test $[num1] -eq $[num2]\r\nthen\r\n    echo '\u4e24\u4e2a\u6570\u5b57\u76f8\u7b49!'\r\nelse\r\n    echo '\u4e24\u4e2a\u6570\u5b57\u4e0d\u76f8\u7b49!'\r\nfi<\/pre>\n

\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n

\u4e24\u4e2a\u6570\u5b57\u76f8\u7b49!<\/pre>\n","protected":false},"excerpt":{"rendered":"

\u5982(\u4ee5\u4e0b\u4e3aPHP\u6d41\u7a0b\u63a7\u5236\u5199\u6cd5)\uff1a < ?php if (isset($_GET[“q”])) { sea […]<\/p>\n","protected":false},"author":1481,"featured_media":162406,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-162202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=162202"}],"version-history":[{"count":6,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162202\/revisions"}],"predecessor-version":[{"id":162407,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162202\/revisions\/162407"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/162406"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=162202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=162202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=162202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}