{"id":18125,"date":"2024-11-18T09:48:01","date_gmt":"2024-11-18T01:48:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18125\/"},"modified":"2024-11-18T09:48:01","modified_gmt":"2024-11-18T01:48:01","slug":"linux%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%bashell%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18125\/","title":{"rendered":"linux\u600e\u4e48\u521b\u5efashell\u811a\u672c"},"content":{"rendered":"<blockquote><p>\n  \u521b\u5efa linux shell \u811a\u672c\u7684\u6b65\u9aa4\uff1a1. \u521b\u5efa\u4e00\u4e2a &#8220;.sh&#8221; \u6269\u5c55\u540d\u7684\u6587\u672c\u6587\u4ef6\uff1b2. \u7f16\u5199 shell \u811a\u672c\u4ee3\u7801\uff1b3. \u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\u4e3a\u53ef\u6267\u884c\uff08chmod +x\uff09\uff1b4. \u8fd0\u884c\u811a\u672c\uff08.\/\u6587\u4ef6\u540d\u6216 bash \u6587\u4ef6\u540d\uff09\u3002\u793a\u4f8b\u811a\u672c\uff1a#!\/bin\/bash\uff0cecho &#8220;hello world!&#8221;\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060313092049620.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u521b\u5efashell\u811a\u672c\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u521b\u5efashell\u811a\u672c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u521b\u5efa Linux shell \u811a\u672c<\/strong><\/p>\n<p>\u5728 Linux \u4e2d\u521b\u5efa shell \u811a\u672c\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6<\/strong><\/p>\n<p>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982 nano \u6216 vi\uff09\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u6269\u5c55\u540d\u8bbe\u7f6e\u4e3a &#8220;.sh&#8221;\u3002<\/p>\n<p><strong>2. \u8f93\u5165 shell \u811a\u672c\u4ee3\u7801<\/strong><\/p>\n<p>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4f60\u7684 shell \u811a\u672c\u4ee3\u7801\uff0c\u786e\u4fdd\u4ee5\u9002\u5f53\u7684\u8bed\u6cd5\u7f16\u5199\u3002<\/p>\n<p><strong>3. \u8bbe\u7f6e\u6587\u4ef6\u6743\u9650<\/strong><\/p>\n<p>\u4e00\u65e6\u4f60\u7f16\u5199\u4e86\u811a\u672c\uff0c\u4f60\u9700\u8981\u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\uff0c\u4ee5\u4fbf\u811a\u672c\u53ef\u4ee5\u88ab\u6267\u884c\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>chmod +x &lt;\u6587\u4ef6\u540d&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<p>\u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8fd0\u884c shell \u811a\u672c\uff1a<\/p>\n<ul>\n<li>\u5728\u7ec8\u7aef\u4e2d\u952e\u5165\u811a\u672c\u540d\u79f0\uff1a<\/li>\n<\/ul>\n<pre>.\/&lt;\u6587\u4ef6\u540d&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u4f7f\u7528 bash \u547d\u4ee4\uff1a<\/li>\n<\/ul>\n<pre>bash &lt;\u6587\u4ef6\u540d&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u811a\u672c<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b shell \u811a\u672c\uff1a<\/p>\n<pre>#!\/bin\/bash\n\necho \"Hello World!\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u811a\u672c\u5c06\u6253\u5370 &#8220;Hello World!&#8221; \u5230\u7ec8\u7aef\u7a97\u53e3\u3002<\/p>\n<p><strong>\u63d0\u793a<\/strong><\/p>\n<ul>\n<li>\u7b2c\u4e00\u884c #!\/bin\/bash \u6307\u5b9a\u4e86\u8981\u7528\u6765\u89e3\u91ca\u811a\u672c\u7684 shell\u3002\u5bf9\u4e8e shell \u811a\u672c\uff0c\u8fd9\u901a\u5e38\u662f \/bin\/bash\u3002<\/li>\n<li>\u786e\u4fdd\u4f60\u7684\u811a\u672c\u6ca1\u6709\u8bed\u6cd5\u9519\u8bef\uff0c\u5426\u5219\u5b83\u5c06\u65e0\u6cd5\u8fd0\u884c\u3002<\/li>\n<li>\u4f7f\u7528\u6ce8\u91ca\u6765\u89e3\u91ca\u4f60\u7684\u4ee3\u7801\uff0c\u4ee5\u4fbf\u5c06\u6765\u66f4\u5bb9\u6613\u7406\u89e3\u3002<\/li>\n<li>\u9075\u5faa Linux Shell \u811a\u672c\u7ea6\u5b9a\uff0c\u4f8b\u5982\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\u548c\u4e0b\u5212\u7ebf\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u521b\u5efa\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u521b\u5efa linux shell \u811a\u672c\u7684\u6b65\u9aa4\uff1a1. \u521b\u5efa\u4e00\u4e2a &#8220;.sh&#8221; \u6269\u5c55\u540d\u7684\u6587\u672c\u6587\u4ef6\uff1b2. \u7f16\u5199 shell \u811a\u672c\u4ee3\u7801\uff1b3. \u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\u4e3a\u53ef\u6267\u884c\uff08chmod +x\uff09\uff1b4. \u8fd0\u884c\u811a\u672c\uff08.\/\u6587\u4ef6\u540d\u6216 bash \u6587\u4ef6\u540d\uff09\u3002\u793a\u4f8b\u811a\u672c\uff1a#!\/bin\/bash\uff0cecho &#8220;hello world!&#8221; \u5982\u4f55\u521b\u5efa Linux shell \u811a\u672c \u5728 Linux \u4e2d\u521b\u5efa shell \u811a\u672c\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6 \u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982 nano \u6216 vi\uff09\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u6269\u5c55\u540d\u8bbe\u7f6e\u4e3a &#8220;.sh&#8221;\u3002 2. \u8f93\u5165 shell \u811a\u672c\u4ee3\u7801 \u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4f60\u7684 shell \u811a\u672c\u4ee3\u7801\uff0c\u786e\u4fdd\u4ee5\u9002\u5f53\u7684\u8bed\u6cd5\u7f16\u5199\u3002 3. \u8bbe\u7f6e\u6587\u4ef6\u6743\u9650 \u4e00\u65e6\u4f60\u7f16\u5199\u4e86\u811a\u672c\uff0c\u4f60\u9700\u8981\u8bbe\u7f6e\u6587\u4ef6\u6743\u9650\uff0c\u4ee5\u4fbf\u811a\u672c\u53ef\u4ee5\u88ab\u6267\u884c\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a chmod +x &lt;\u6587\u4ef6\u540d&gt; \u767b\u5f55\u540e\u590d\u5236 4. \u8fd0\u884c\u811a\u672c \u6709\u4e24\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8fd0\u884c shell \u811a\u672c\uff1a \u5728\u7ec8\u7aef\u4e2d\u952e\u5165\u811a\u672c\u540d\u79f0\uff1a .\/&lt;\u6587\u4ef6\u540d&gt; \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18125","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18125"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18125\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}