{"id":114,"date":"2019-02-10T18:02:10","date_gmt":"2019-02-10T10:02:10","guid":{"rendered":"http:\/\/b.yesiyu.top\/?p=114"},"modified":"2019-02-10T18:02:10","modified_gmt":"2019-02-10T10:02:10","slug":"shell-%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/b.yesiyu.top\/?p=114","title":{"rendered":"Shell \u6559\u7a0b"},"content":{"rendered":"<h1>Shell \u6559\u7a0b<\/h1>\n<p>Shell \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<\/p>\n<p>Shell \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<\/p>\n<p>Ken Thompson \u7684 sh \u662f\u7b2c\u4e00\u79cd Unix Shell\uff0cWindows Explorer \u662f\u4e00\u4e2a\u5178\u578b\u7684\u56fe\u5f62\u754c\u9762 Shell\u3002<\/p>\n<p><a href=\"http:\/\/www.runoob.com\/try\/showbash.php?filename=helloworld\" target=\"_blank\" rel=\"noopener\"><strong>Shell \u5728\u7ebf\u5de5\u5177<\/strong><\/a><\/p>\n<hr \/>\n<h2>Shell \u811a\u672c<\/h2>\n<p>Shell \u811a\u672c\uff08shell script\uff09\uff0c\u662f\u4e00\u79cd\u4e3a shell \u7f16\u5199\u7684\u811a\u672c\u7a0b\u5e8f\u3002<\/p>\n<p>\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<p>\u7531\u4e8e\u4e60\u60ef\u7684\u539f\u56e0\uff0c\u7b80\u6d01\u8d77\u89c1\uff0c\u672c\u6587\u51fa\u73b0\u7684 &#8220;shell\u7f16\u7a0b&#8221; \u90fd\u662f\u6307 shell \u811a\u672c\u7f16\u7a0b\uff0c\u4e0d\u662f\u6307\u5f00\u53d1 shell \u81ea\u8eab\u3002<\/p>\n<hr \/>\n<h2>Shell \u73af\u5883<\/h2>\n<p>Shell \u7f16\u7a0b\u8ddf java\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<p>Linux \u7684 Shell \u79cd\u7c7b\u4f17\u591a\uff0c\u5e38\u89c1\u7684\u6709\uff1a<\/p>\n<ul>\n<li>Bourne Shell\uff08\/usr\/bin\/sh\u6216\/bin\/sh\uff09<\/li>\n<li>Bourne Again Shell\uff08\/bin\/bash\uff09<\/li>\n<li>C Shell\uff08\/usr\/bin\/csh\uff09<\/li>\n<li>K Shell\uff08\/usr\/bin\/ksh\uff09<\/li>\n<li>Shell for Root\uff08\/sbin\/sh\uff09<\/li>\n<li>\u2026\u2026<\/li>\n<\/ul>\n<p>\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<p>\u5728\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4eba\u4eec\u5e76\u4e0d\u533a\u5206 Bourne Shell \u548c Bourne Again Shell\uff0c\u6240\u4ee5\uff0c\u50cf\u00a0<strong>#!\/bin\/sh<\/strong>\uff0c\u5b83\u540c\u6837\u4e5f\u53ef\u4ee5\u6539\u4e3a\u00a0<strong>#!\/bin\/bash<\/strong>\u3002<\/p>\n<p><span class=\"marked\">#!<\/span>\u00a0\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<hr \/>\n<h2>\u7b2c\u4e00\u4e2ashell\u811a\u672c<\/h2>\n<p>\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<p>\u8f93\u5165\u4e00\u4e9b\u4ee3\u7801\uff0c\u7b2c\u4e00\u884c\u4e00\u822c\u662f\u8fd9\u6837\uff1a<\/p>\n<div class=\"example\">\n<h2 class=\"example\">\u5b9e\u4f8b<\/h2>\n<div class=\"example_code\">#!\/bin\/bash<br \/>\necho\u00a0&#8220;Hello World !&#8221;<\/div>\n<p><a class=\"showbtn\" href=\"http:\/\/www.runoob.com\/try\/runcode.php?filename=helloworld&amp;type=bash\" target=\"_blank\" rel=\"noopener\">\u8fd0\u884c\u5b9e\u4f8b \u00bb<\/a><\/div>\n<p><span class=\"marked\">#!<\/span>\u00a0\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<p>echo \u547d\u4ee4\u7528\u4e8e\u5411\u7a97\u53e3\u8f93\u51fa\u6587\u672c\u3002<\/p>\n<h3>\u8fd0\u884c Shell \u811a\u672c\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a<\/h3>\n<p><strong>1\u3001\u4f5c\u4e3a\u53ef\u6267\u884c\u7a0b\u5e8f<\/strong><\/p>\n<p>\u5c06\u4e0a\u9762\u7684\u4ee3\u7801\u4fdd\u5b58\u4e3a test.sh\uff0c\u5e76 cd \u5230\u76f8\u5e94\u76ee\u5f55\uff1a<\/p>\n<pre class=\"prettyprint prettyprinted\"><span class=\"pln\">chmod <\/span><span class=\"pun\">+<\/span><span class=\"pln\">x <\/span><span class=\"pun\">.\/<\/span><span class=\"pln\">test<\/span><span class=\"pun\">.<\/span><span class=\"pln\">sh  <\/span><span class=\"com\">#\u4f7f\u811a\u672c\u5177\u6709\u6267\u884c\u6743\u9650<\/span>\r\n<span class=\"pun\">.\/<\/span><span class=\"pln\">test<\/span><span class=\"pun\">.<\/span><span class=\"pln\">sh  <\/span><span class=\"com\">#\u6267\u884c\u811a\u672c<\/span><\/pre>\n<p>\u6ce8\u610f\uff0c\u4e00\u5b9a\u8981\u5199\u6210\u00a0<span class=\"marked\">.\/test.sh<\/span>\uff0c\u800c\u4e0d\u662f\u00a0<b>test.sh<\/b>\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<p><strong>2\u3001\u4f5c\u4e3a\u89e3\u91ca\u5668\u53c2\u6570<\/strong><\/p>\n<p>\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<pre class=\"prettyprint prettyprinted\"><span class=\"str\">\/bin\/<\/span><span class=\"pln\">sh test<\/span><span class=\"pun\">.<\/span><span class=\"pln\">sh\r\n<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">bin<\/span><span class=\"pun\">\/<\/span><span class=\"pln\">php test<\/span><span class=\"pun\">.<\/span><span class=\"pln\">php<\/span><\/pre>\n<p>\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":"<p>Shell \u6559\u7a0b Shell \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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/b.yesiyu.top\/?p=114\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cShell \u6559\u7a0b\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-114","post","type-post","status-publish","format-standard","hentry","category-liunx-"],"_links":{"self":[{"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=\/wp\/v2\/posts\/114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=114"}],"version-history":[{"count":1,"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":115,"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=\/wp\/v2\/posts\/114\/revisions\/115"}],"wp:attachment":[{"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/b.yesiyu.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}