{"id":162083,"date":"2019-11-03T10:00:47","date_gmt":"2019-11-03T02:00:47","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=162083"},"modified":"2019-10-22T09:26:35","modified_gmt":"2019-10-22T01:26:35","slug":"learning-shell-tutorial","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/learning-shell-tutorial.html","title":{"rendered":"\u5b66\u4e60Shell \u6559\u7a0b"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nShell \u662f\u4e00\u4e2a\u7528 C \u8bed\u8a00\u7f16\u5199\u7684\u7a0b\u5e8f\uff0c\u5b83\u662f\u7528\u6237\u4f7f\u7528 Linux \u7684\u6865\u6881\u3002Shell \u65e2\u662f\u4e00\u79cd\u547d\u4ee4\u8bed\u8a00\uff0c\u53c8\u662f\u4e00\u79cd\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u3002
\nShell \u662f\u6307\u4e00\u79cd\u5e94\u7528\u7a0b\u5e8f\uff0c\u8fd9\u4e2a\u5e94\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u4e00\u4e2a\u754c\u9762\uff0c\u7528\u6237\u901a\u8fc7\u8fd9\u4e2a\u754c\u9762\u8bbf\u95ee\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u7684\u670d\u52a1\u3002
\nKen Thompson \u7684 sh \u662f\u7b2c\u4e00\u79cd Unix Shell\uff0cWindows Explorer \u662f\u4e00\u4e2a\u5178\u578b\u7684\u56fe\u5f62\u754c\u9762 Shell\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

Shell \u811a\u672c<\/strong><\/div>\n

Shell \u811a\u672c\uff08shell script\uff09\uff0c\u662f\u4e00\u79cd\u4e3a shell \u7f16\u5199\u7684\u811a\u672c\u7a0b\u5e8f\u3002<\/p>\n

\u4e1a\u754c\u6240\u8bf4\u7684 shell \u901a\u5e38\u90fd\u662f\u6307 shell \u811a\u672c\uff0c\u4f46\u8bfb\u8005\u670b\u53cb\u8981\u77e5\u9053\uff0cshell \u548c shell script \u662f\u4e24\u4e2a\u4e0d\u540c\u7684\u6982\u5ff5\u3002<\/p>\n

\u7531\u4e8e\u4e60\u60ef\u7684\u539f\u56e0\uff0c\u7b80\u6d01\u8d77\u89c1\uff0c\u672c\u6587\u51fa\u73b0\u7684 \"shell\u7f16\u7a0b\" \u90fd\u662f\u6307 shell \u811a\u672c\u7f16\u7a0b\uff0c\u4e0d\u662f\u6307\u5f00\u53d1 shell \u81ea\u8eab\u3002<\/p>\n

Shell \u73af\u5883<\/strong><\/div>\n

Shell \u7f16\u7a0b\u8ddf JavaScript\u3001php \u7f16\u7a0b\u4e00\u6837\uff0c\u53ea\u8981\u6709\u4e00\u4e2a\u80fd\u7f16\u5199\u4ee3\u7801\u7684\u6587\u672c\u7f16\u8f91\u5668\u548c\u4e00\u4e2a\u80fd\u89e3\u91ca\u6267\u884c\u7684\u811a\u672c\u89e3\u91ca\u5668\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n

Linux \u7684 Shell \u79cd\u7c7b\u4f17\u591a\uff0c\u5e38\u89c1\u7684\u6709\uff1a<\/p>\n

Bourne Shell\uff08\/usr\/bin\/sh\u6216\/bin\/sh\uff09
\nBourne Again Shell\uff08\/bin\/bash\uff09
\nC Shell\uff08\/usr\/bin\/csh\uff09
\nK Shell\uff08\/usr\/bin\/ksh\uff09
\nShell for Root\uff08\/sbin\/sh\uff09
\n\u2026\u2026
\n\u672c\u6559\u7a0b\u5173\u6ce8\u7684\u662f Bash\uff0c\u4e5f\u5c31\u662f Bourne Again Shell\uff0c\u7531\u4e8e\u6613\u7528\u548c\u514d\u8d39\uff0cBash \u5728\u65e5\u5e38\u5de5\u4f5c\u4e2d\u88ab\u5e7f\u6cdb\u4f7f\u7528\u3002\u540c\u65f6\uff0cBash \u4e5f\u662f\u5927\u591a\u6570Linux \u7cfb\u7edf\u9ed8\u8ba4\u7684 Shell\u3002<\/p>\n

\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4eba\u4eec\u5e76\u4e0d\u533a\u5206 Bourne Shell \u548c Bourne Again Shell\uff0c\u6240\u4ee5\uff0c\u50cf #!\/bin\/sh\uff0c\u5b83\u540c\u6837\u4e5f\u53ef\u4ee5\u6539\u4e3a #!\/bin\/bash\u3002<\/p>\n

#! \u544a\u8bc9\u7cfb\u7edf\u5176\u540e\u8def\u5f84\u6240\u6307\u5b9a\u7684\u7a0b\u5e8f\u5373\u662f\u89e3\u91ca\u6b64\u811a\u672c\u6587\u4ef6\u7684 Shell \u7a0b\u5e8f\u3002<\/p>\n

\u7b2c\u4e00\u4e2ashell\u811a\u672c<\/strong><\/div>\n

\u6253\u5f00\u6587\u672c\u7f16\u8f91\u5668(\u53ef\u4ee5\u4f7f\u7528 vi\/vim \u547d\u4ee4\u6765\u521b\u5efa\u6587\u4ef6)\uff0c\u65b0\u5efa\u4e00\u4e2a\u6587\u4ef6 test.sh\uff0c\u6269\u5c55\u540d\u4e3a sh\uff08sh\u4ee3\u8868shell\uff09\uff0c\u6269\u5c55\u540d\u5e76\u4e0d\u5f71\u54cd\u811a\u672c\u6267\u884c\uff0c\u89c1\u540d\u77e5\u610f\u5c31\u597d\uff0c\u5982\u679c\u4f60\u7528 php \u5199 shell \u811a\u672c\uff0c\u6269\u5c55\u540d\u5c31\u7528 php \u597d\u4e86\u3002<\/p>\n

\u8f93\u5165\u4e00\u4e9b\u4ee3\u7801\uff0c\u7b2c\u4e00\u884c\u4e00\u822c\u662f\u8fd9\u6837\uff1a<\/p>\n

\u5b9e\u4f8b\r\n#!\/bin\/bash\r\necho \"Hello World !\"\r\n\r\n\u8fd0\u884c\u5b9e\u4f8b \u00bb<\/pre>\n

#! \u662f\u4e00\u4e2a\u7ea6\u5b9a\u7684\u6807\u8bb0\uff0c\u5b83\u544a\u8bc9\u7cfb\u7edf\u8fd9\u4e2a\u811a\u672c\u9700\u8981\u4ec0\u4e48\u89e3\u91ca\u5668\u6765\u6267\u884c\uff0c\u5373\u4f7f\u7528\u54ea\u4e00\u79cd Shell\u3002<\/p>\n

echo \u547d\u4ee4\u7528\u4e8e\u5411\u7a97\u53e3\u8f93\u51fa\u6587\u672c\u3002<\/p>\n

\u8fd0\u884c Shell \u811a\u672c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a<\/strong><\/span><\/div>\n

1\u3001\u4f5c\u4e3a\u53ef\u6267\u884c\u7a0b\u5e8f<\/strong><\/p>\n

\u5c06\u4e0a\u9762\u7684\u4ee3\u7801\u4fdd\u5b58\u4e3a test.sh\uff0c\u5e76 cd \u5230\u76f8\u5e94\u76ee\u5f55\uff1a<\/p>\n

chmod +x .\/test.sh  #\u4f7f\u811a\u672c\u5177\u6709\u6267\u884c\u6743\u9650\r\n.\/test.sh  #\u6267\u884c\u811a\u672c<\/pre>\n

\u6ce8\u610f\uff0c\u4e00\u5b9a\u8981\u5199\u6210 .\/test.sh\uff0c\u800c\u4e0d\u662f test.sh\uff0c\u8fd0\u884c\u5176\u5b83\u4e8c\u8fdb\u5236\u7684\u7a0b\u5e8f\u4e5f\u4e00\u6837\uff0c\u76f4\u63a5\u5199 test.sh\uff0clinux \u7cfb\u7edf\u4f1a\u53bb PATH \u91cc\u5bfb\u627e\u6709\u6ca1\u6709\u53eb test.sh \u7684\uff0c\u800c\u53ea\u6709 \/bin, \/sbin, \/usr\/bin\uff0c\/usr\/sbin \u7b49\u5728 PATH \u91cc\uff0c\u4f60\u7684\u5f53\u524d\u76ee\u5f55\u901a\u5e38\u4e0d\u5728 PATH \u91cc\uff0c\u6240\u4ee5\u5199\u6210 test.sh \u662f\u4f1a\u627e\u4e0d\u5230\u547d\u4ee4\u7684\uff0c\u8981\u7528 .\/test.sh \u544a\u8bc9\u7cfb\u7edf\u8bf4\uff0c\u5c31\u5728\u5f53\u524d\u76ee\u5f55\u627e\u3002<\/p>\n

2\u3001\u4f5c\u4e3a\u89e3\u91ca\u5668\u53c2\u6570<\/strong><\/p>\n

\u8fd9\u79cd\u8fd0\u884c\u65b9\u5f0f\u662f\uff0c\u76f4\u63a5\u8fd0\u884c\u89e3\u91ca\u5668\uff0c\u5176\u53c2\u6570\u5c31\u662f shell \u811a\u672c\u7684\u6587\u4ef6\u540d\uff0c\u5982\uff1a<\/p>\n

\/bin\/sh test.sh\r\n\/bin\/php test.php<\/pre>\n

\u8fd9\u79cd\u65b9\u5f0f\u8fd0\u884c\u7684\u811a\u672c\uff0c\u4e0d\u9700\u8981\u5728\u7b2c\u4e00\u884c\u6307\u5b9a\u89e3\u91ca\u5668\u4fe1\u606f\uff0c\u5199\u4e86\u4e5f\u6ca1\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

Shell \u811a\u672c\uff08shell script\uff09\uff0c\u662f\u4e00\u79cd\u4e3a shell \u7f16\u5199\u7684\u811a\u672c\u7a0b\u5e8f\u3002 \u4e1a\u754c\u6240\u8bf4\u7684 shell […]<\/p>\n","protected":false},"author":1481,"featured_media":162085,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-162083","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\/162083","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=162083"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162083\/revisions"}],"predecessor-version":[{"id":162087,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/162083\/revisions\/162087"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/162085"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=162083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=162083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=162083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}