{"id":18111,"date":"2024-11-18T13:32:43","date_gmt":"2024-11-18T05:32:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18111\/"},"modified":"2024-11-18T13:32:43","modified_gmt":"2024-11-18T05:32:43","slug":"linux%e6%80%8e%e4%b9%88%e8%bf%90%e8%a1%8c%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18111\/","title":{"rendered":"linux\u600e\u4e48\u8fd0\u884c\u811a\u672c"},"content":{"rendered":"<blockquote><p>\n  \u8981\u5728 linux \u4e2d\u8fd0\u884c\u811a\u672c\uff0c\u8bf7\u5148\u786e\u4fdd\u811a\u672c\u5177\u6709\u53ef\u6267\u884c\u6743\u9650\uff08ls -l script_name\uff09\uff0c\u7136\u540e\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u8fd0\u884c\u811a\u672c\uff1a\u547d\u4ee4\u884c\uff08.\/script_name\uff09\u3001bash \u547d\u4ee4\uff08bash script_name\uff09\u3001python \u547d\u4ee4\uff08python script_name.py\uff09\u3002\u811a\u672c\u53ef\u4ee5\u4ece\u547d\u4ee4\u884c\u63a5\u6536\u53c2\u6570\uff0c\u5e76\u4f7f\u7528 sys.argv \u6570\u7ec4\u8bbf\u95ee\u5b83\u4eec\u3002\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u201cpermission denied\u201d\uff08\u68c0\u67e5\u53ef\u6267\u884c\u6743\u9650\uff09\uff0c\u201ccommand not found\u201d\uff08\u68c0\u67e5\u8def\u5f84\u662f\u5426\u6b63\u786e\uff09\u548c\u201c\u811a\u672c\u6ca1\u6709\u8fd0\u884c\u201d\uff08\u68c0\u67e5\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060312181858885.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u8fd0\u884c\u811a\u672c\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u8fd0\u884c\u811a\u672c\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Linux \u4e2d\u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<p>\u8981\u8fd0\u884c Linux \u811a\u672c\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u786e\u5b9a\u811a\u672c\u6743\u9650<\/strong><\/p>\n<p>\u786e\u4fdd\u811a\u672c\u5177\u6709\u53ef\u6267\u884c\u6743\u9650\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u6743\u9650\uff1a<\/p>\n<pre>ls -l script_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u201c\u6743\u9650\u201d\u5217\u4e2d\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e0d\u662f\u201c-\u201d\uff0c\u5219\u9700\u8981\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6dfb\u52a0\u6743\u9650\uff1a<\/p>\n<pre>chmod +x script_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u8fd0\u884c\u811a\u672c<\/strong><\/p>\n<p>\u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<ul>\n<li><strong>\u5728\u547d\u4ee4\u884c\u4e2d\uff1a<\/strong><\/li>\n<\/ul>\n<pre>.\/script_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><strong>\u4f7f\u7528 Bash \u547d\u4ee4\uff1a<\/strong><\/li>\n<\/ul>\n<pre>bash script_name<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li><strong>\u4f7f\u7528  \u547d\u4ee4\uff08\u5bf9\u4e8e Python \u811a\u672c\uff09\uff1a<\/strong><\/li>\n<\/ul>\n<pre>python script_name.py<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u4f7f\u7528\u53c2\u6570\u4f20\u9012\u6570\u636e<\/strong><\/p>\n<p>\u811a\u672c\u53ef\u4ee5\u4ece\u547d\u4ee4\u884c\u63a5\u6536\u53c2\u6570\u3002\u5728\u811a\u672c\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528 sys.argv \u6570\u7ec4\u8bbf\u95ee\u53c2\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>import sys\n\nprint(sys.argv[1])  # \u8bbf\u95ee\u7b2c\u4e00\u4e2a\u53c2\u6570<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u5e38\u89c1\u95ee\u9898<\/strong><\/p>\n<ul>\n<li> <strong>\u201cPermission denied\u201d\u9519\u8bef\uff1a<\/strong>\u786e\u4fdd\u811a\u672c\u5177\u6709\u53ef\u6267\u884c\u6743\u9650\uff08\u8bf7\u53c2\u89c1\u6b65\u9aa4 1\uff09\u3002<\/li>\n<li> <strong>\u201cCommand not found\u201d\u9519\u8bef\uff1a<\/strong>\u68c0\u67e5\u811a\u672c\u6587\u4ef6\u7684\u8def\u5f84\u662f\u5426\u662f\u6b63\u786e\u7684\u3002<\/li>\n<li> <strong>\u811a\u672c\u6ca1\u6709\u8fd0\u884c\uff1a<\/strong>\u786e\u4fdd\u811a\u672c\u7684\u8bed\u6cd5\u662f\u6b63\u786e\u7684\uff0c\u5e76\u4e14\u4e0d\u5b58\u5728\u4efb\u4f55\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a hello_world.sh \u7684\u811a\u672c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>#!\/bin\/bash\n\necho \"Hello, world!\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e3a\u811a\u672c\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650\uff1a<\/p>\n<pre>chmod +x hello_world.sh<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<pre>.\/hello_world.sh<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre>Hello, world!<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8fd0\u884c\u811a\u672c\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>\u8981\u5728 linux \u4e2d\u8fd0\u884c\u811a\u672c\uff0c\u8bf7\u5148\u786e\u4fdd\u811a\u672c\u5177\u6709\u53ef\u6267\u884c\u6743\u9650\uff08ls -l script_name\uff09\uff0c\u7136\u540e\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\u8fd0\u884c\u811a\u672c\uff1a\u547d\u4ee4\u884c\uff08.\/script_name\uff09\u3001bash \u547d\u4ee4\uff08bash script_name\uff09\u3001python \u547d\u4ee4\uff08python script_name.py\uff09\u3002\u811a\u672c\u53ef\u4ee5\u4ece\u547d\u4ee4\u884c\u63a5\u6536\u53c2\u6570\uff0c\u5e76\u4f7f\u7528 sys.argv \u6570\u7ec4\u8bbf\u95ee\u5b83\u4eec\u3002\u5e38\u89c1\u95ee\u9898\u5305\u62ec\u201cpermission denied\u201d\uff08\u68c0\u67e5\u53ef\u6267\u884c\u6743\u9650\uff09\uff0c\u201ccommand not found\u201d\uff08\u68c0\u67e5\u8def\u5f84\u662f\u5426\u6b63\u786e\uff09\u548c\u201c\u811a\u672c\u6ca1\u6709\u8fd0\u884c\u201d\uff08\u68c0\u67e5 \u5982\u4f55\u5728 Linux \u4e2d\u8fd0\u884c\u811a\u672c \u8981\u8fd0\u884c Linux \u811a\u672c\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u786e\u5b9a\u811a\u672c\u6743\u9650 \u786e\u4fdd\u811a\u672c\u5177\u6709\u53ef\u6267\u884c\u6743\u9650\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u68c0\u67e5\u6743\u9650\uff1a ls -l script_name \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u201c\u6743\u9650\u201d\u5217\u4e2d\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e0d\u662f\u201c-\u201d\uff0c\u5219\u9700\u8981\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6dfb\u52a0\u6743\u9650\uff1a chmod +x script_name \u767b\u5f55\u540e\u590d\u5236 2. \u8fd0\u884c\u811a\u672c \u6709\u51e0\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8fd0\u884c\u811a\u672c\uff1a \u5728\u547d\u4ee4\u884c\u4e2d\uff1a .\/script_name \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 Bash \u547d\u4ee4\uff1a bash script_name \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 \u547d\u4ee4\uff08\u5bf9\u4e8e Python \u811a\u672c\uff09\uff1a python script_name.py \u767b\u5f55\u540e\u590d\u5236 3. \u4f7f\u7528\u53c2\u6570\u4f20\u9012\u6570\u636e \u811a\u672c\u53ef\u4ee5\u4ece\u547d\u4ee4\u884c\u63a5\u6536\u53c2\u6570\u3002\u5728\u811a\u672c\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528 sys.argv [&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-18111","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18111","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=18111"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18111\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}