{"id":63868,"date":"2025-04-29T17:30:55","date_gmt":"2025-04-29T09:30:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63868\/"},"modified":"2025-04-29T17:30:55","modified_gmt":"2025-04-29T09:30:55","slug":"linux%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aashell%e8%84%9a%e6%9c%ac-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63868\/","title":{"rendered":"linux\u600e\u4e48\u521b\u5efa\u4e00\u4e2ashell\u811a\u672c"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5728 linux \u4e2d\u521b\u5efa shell \u811a\u672c\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a\u521b\u5efa\u5e76\u547d\u540d\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u6269\u5c55\u540d\u4e3a .sh\u3002\u5728\u6587\u4ef6\u7b2c\u4e00\u884c\u6dfb\u52a0 shebang \u884c\uff0c\u6307\u5b9a\u89e3\u91ca\u5668\uff08\u4f8b\u5982\uff1a#!\/bin\/bash\uff09\u3002\u7f16\u5199\u811a\u672c\u547d\u4ee4\u3002\u4fdd\u5b58\u6587\u4ef6\u5e76\u8d4b\u4e88\u5176\u6267\u884c\u6743\u9650\uff08chmod +x filename.sh\uff09\u3002\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u952e\u5165\u811a\u672c\u540d\u79f0\uff08\u4e0d\u5e26\u6269\u5c55\u540d\uff09\u6765\u6267\u884c\u5b83\uff08\u4f8b\u5982\uff1a.\/filename\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/27\/2024062701463640751.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u521b\u5efa\u4e00\u4e2ashell\u811a\u672c\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u521b\u5efa\u4e00\u4e2ashell\u811a\u672c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Linux \u4e2d\u521b\u5efa Shell \u811a\u672c<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a shell \u811a\u672c\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff1a<\/strong>\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f8b\u5982 nano \u6216 vim\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u3002<\/li>\n<li> <strong>\u6dfb\u52a0 Shebang \u884c\uff1a<\/strong>\u5728\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/li>\n<\/ol>\n<pre>#!\/bin\/bash<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>Shebang \u884c\u544a\u8bc9\u7cfb\u7edf\u4f7f\u7528\u54ea\u4e2a\u89e3\u91ca\u5668\u6765\u6267\u884c\u811a\u672c\u3002<\/p>\n<ol>\n<li> <strong>\u7f16\u5199\u811a\u672c\u547d\u4ee4\uff1a<\/strong>\u5728 Shebang \u884c\u4e0b\u65b9\uff0c\u7f16\u5199\u5fc5\u8981\u7684 shell \u547d\u4ee4\u6765\u5b9e\u73b0\u811a\u672c\u7684\u529f\u80fd\u3002<\/li>\n<li> <strong>\u4fdd\u5b58\u6587\u4ef6\uff1a<\/strong>\u4f7f\u7528 .sh \u6269\u5c55\u540d\u4fdd\u5b58\u6587\u4ef6\uff0c\u4f8b\u5982 myscript.sh\u3002<\/li>\n<li> <strong>\u8d4b\u4e88\u811a\u672c\u6267\u884c\u6743\u9650\uff1a<\/strong>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u8d4b\u4e88\u811a\u672c\u6267\u884c\u6743\u9650\uff1a<\/li>\n<\/ol>\n<pre>chmod +x myscript.sh<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u952e\u5165\u811a\u672c\u540d\u79f0\uff08\u4e0d\u5e26 .sh \u6269\u5c55\u540d\uff09\u6765\u6267\u884c\u811a\u672c\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>.\/myscript<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u811a\u672c<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a hello.sh \u7684\u7b80\u5355 shell \u811a\u672c\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>#!\/bin\/bash\n\necho \"Hello, world!\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4fdd\u5b58\u5e76\u8d4b\u4e88\u6267\u884c\u6743\u9650\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6267\u884c\u811a\u672c\uff1a<\/p>\n<pre>.\/hello<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u5c06\u6253\u5370\u6d88\u606f &#8220;Hello, world!&#8221; \u5230\u7ec8\u7aef\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u5728 linux \u4e2d\u521b\u5efa shell \u811a\u672c\uff0c\u8bf7\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a\u521b\u5efa\u5e76\u547d\u540d\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u6269\u5c55\u540d\u4e3a .sh\u3002\u5728\u6587\u4ef6\u7b2c\u4e00\u884c\u6dfb\u52a0 shebang \u884c\uff0c\u6307\u5b9a\u89e3\u91ca\u5668\uff08\u4f8b\u5982\uff1a#!\/bin\/bash\uff09\u3002\u7f16\u5199\u811a\u672c\u547d\u4ee4\u3002\u4fdd\u5b58\u6587\u4ef6\u5e76\u8d4b\u4e88\u5176\u6267\u884c\u6743\u9650\uff08chmod +x filename.sh\uff09\u3002\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u952e\u5165\u811a\u672c\u540d\u79f0\uff08\u4e0d\u5e26\u6269\u5c55\u540d\uff09\u6765\u6267\u884c\u5b83\uff08\u4f8b\u5982\uff1a.\/filename\uff09\u3002 \u5982\u4f55\u5728 Linux \u4e2d\u521b\u5efa Shell \u811a\u672c \u521b\u5efa\u4e00\u4e2a shell \u811a\u672c\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff1a\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4f8b\u5982 nano \u6216 vim\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u3002 \u6dfb\u52a0 Shebang \u884c\uff1a\u5728\u6587\u4ef6\u7684\u7b2c\u4e00\u884c\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\uff1a #!\/bin\/bash \u767b\u5f55\u540e\u590d\u5236 Shebang \u884c\u544a\u8bc9\u7cfb\u7edf\u4f7f\u7528\u54ea\u4e2a\u89e3\u91ca\u5668\u6765\u6267\u884c\u811a\u672c\u3002 \u7f16\u5199\u811a\u672c\u547d\u4ee4\uff1a\u5728 Shebang \u884c\u4e0b\u65b9\uff0c\u7f16\u5199\u5fc5\u8981\u7684 shell \u547d\u4ee4\u6765\u5b9e\u73b0\u811a\u672c\u7684\u529f\u80fd\u3002 \u4fdd\u5b58\u6587\u4ef6\uff1a\u4f7f\u7528 .sh \u6269\u5c55\u540d\u4fdd\u5b58\u6587\u4ef6\uff0c\u4f8b\u5982 myscript.sh\u3002 \u8d4b\u4e88\u811a\u672c\u6267\u884c\u6743\u9650\uff1a\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u8d4b\u4e88\u811a\u672c\u6267\u884c\u6743\u9650\uff1a chmod +x myscript.sh \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u952e\u5165\u811a\u672c\u540d\u79f0\uff08\u4e0d\u5e26 .sh \u6269\u5c55\u540d\uff09\u6765\u6267\u884c\u811a\u672c\uff0c\u4f8b\u5982\uff1a .\/myscript \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\u811a\u672c \u4ee5\u4e0b\u662f\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a hello.sh \u7684\u7b80\u5355 shell \u811a\u672c\u7684\u793a\u4f8b\uff1a #!\/bin\/bash [&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-63868","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63868","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=63868"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63868\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63868"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63868"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63868"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}