﻿{"id":858,"date":"2020-06-23T16:50:19","date_gmt":"2020-06-23T08:50:19","guid":{"rendered":"https:\/\/www.linuxmi.com\/?p=858"},"modified":"2020-06-23T16:50:19","modified_gmt":"2020-06-23T08:50:19","slug":"bash","status":"publish","type":"post","link":"https:\/\/www.linuxmi.com\/bash.html","title":{"rendered":"\u5982\u4f55\u6b63\u786e\u7f16\u5199bash\u811a\u672c"},"content":{"rendered":"<p>bash\u811a\u672c\u662f\u5728Linux\u4e0a\u6267\u884c\u548c\u81ea\u52a8\u5316\u4efb\u52a1\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u5b83\u4eec\u5feb\u901f\u3001\u5b89\u5168\u3001\u53ef\u9760\u3002<\/p>\n<p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u770b\u5230\u521b\u5efa\u811a\u672c\u65f6\u7684\u6700\u4f73\u5b9e\u8df5\u6cd5\u5219\uff0c\u6216\u8005\u66f4\u786e\u5207\u5730\u8bf4\uff0c\u5982\u4f55\u6b63\u786e\u5730\u7f16\u5199bash\u811a\u672c\uff0c\u4f7f\u5b83\u53ef\u4ee5\u88ab\u7406\u89e3\uff0c\u6700\u91cd\u8981\u7684\u662f\uff0c\u53ef\u91cd\u590d\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5982\u4f55\u6b63\u786e\u7f16\u5199bash\u811a\u672c<\/strong><\/p>\n<p>\u6211\u4eec\u63d0\u4f9b\u4e86\u4efb\u4f55bash\u5f00\u53d1\u4eba\u5458\u90fd\u5e94\u8be5\u9075\u5faa\u768410\u6761\u5efa\u8bae\u3002<\/p>\n<p><strong>\u8bb0\u5f97\u6dfb\u52a0\u6ce8\u91ca<\/strong><\/p>\n<p>\u6ce8\u91ca\u6709\u52a9\u4e8e\u7406\u89e3\u811a\u672c\u5f00\u53d1\uff0c\u5e76\u4f7f\u5e0c\u671b\u7ee7\u7eed\u6216\u6539\u8fdb\u811a\u672c\u7684\u5176\u4ed6\u5f00\u53d1\u4eba\u5458\u66f4\u5bb9\u6613\u5b8c\u6210\u4efb\u52a1\u3002\u8bf7\u8bb0\u4f4f\uff0c\u5b83\u4eec\u662f\u6307\u793a\u6027\u7684\uff0c\u4e3a\u4e86\u907f\u514d\u6267\u884c\uff0c\u5b83\u4eec\u5fc5\u987b\u88ab\u6ce8\u91ca(\u5b57\u7b26#)\u3002<\/p>\n<p>\u5728Bash\u811a\u672c\u4e2d\u6dfb\u52a0\u6ce8\u91ca\u53ef\u4ee5\u8282\u7701\u4ee5\u540e\u67e5\u770b\u4ee3\u7801\u65f6\u7684\u5927\u91cf\u65f6\u95f4\u548c\u7cbe\u529b\uff0c\u5047\u8bbe\u60a8\u8981\u66f4\u6539\u51e0\u4e2a\u6708\u6216\u51e0\u5e74\u524d\u7f16\u5199\u7684\u811a\u672c\u3002\u9664\u975e\u60a8\u6dfb\u52a0\u6ce8\u91ca\uff0c\u5426\u5219\u60a8\u5c06\u4e0d\u8bb0\u5f97\u4e3a\u4ec0\u4e48\u7f16\u5199\u4e86\u8fd9\u4e9b\u590d\u6742\u7684\u4ee3\u7801\u3002<\/p>\n<p><strong>\u5355\u884c\u6ce8\u91ca\uff1a<\/strong><\/p>\n<p># The script by linuxmi.com, &#8230;..<\/p>\n<p>\u4f8b\u5b50\uff1a<\/p>\n<p>\u201c\uff03\u201d\u7b26\u53f7\u7528\u4e8e\u5728bash\u811a\u672c\u4e2d\u6dfb\u52a0\u5355\u884c\u6ce8\u91ca\u3002\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u201c linuxmi.com.sh\u201d\u7684\u65b0\u6587\u4ef6\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5e26\u6709\u5355\u884c\u6ce8\u91ca\u7684\u811a\u672c\u3002<\/p>\n<p>#!\/bin\/bash<\/p>\n<p># \u4e24\u4e2a\u6570\u503c\u76f8\u52a0<br \/>\n((sum=17+20))<\/p>\n<p>#\u6253\u5370\u7ed3\u679c<br \/>\necho $sum<\/p>\n<p><strong>\u591a\u884c\u6ce8\u91ca\uff1a<\/strong><\/p>\n<p>\u5728bash\u4e2d\u53ef\u4ee5\u4ee5\u5404\u79cd\u65b9\u5f0f\u4f7f\u7528\u591a\u884c\u6ce8\u91ca\u3002\u4e0b\u9762\u7684\u793a\u4f8b\u663e\u793a\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u5728\u8fd9\u91cc\uff0c&#8217;:&#8217;\u548c&#8221; &#8216; &#8220;\u7b26\u53f7\u7528\u4e8e\u5728bash\u811a\u672c\u4e2d\u6dfb\u52a0\u591a\u884c\u6ce8\u91ca\u3002\u4e0b\u9762\u7684\u811a\u672c\u5c06\u8ba1\u7b977&#215;9\u7684\u79ef\u3002<\/p>\n<p>#!\/bin\/bash<br \/>\n<strong><span style=\"color: #ff0000;\">: &#8216;<\/span><\/strong><br \/>\n\u4e0b\u9762\u662f\u4e24\u4e2a\u6570\u7684\u76f8\u4e58\u7684\u79ef<br \/>\n\u8fd9\u91cc\u662f7\u4e589<br \/>\n<strong><span style=\"color: #ff0000;\">&#8216;<\/span><\/strong><br \/>\n((area=7*9))<br \/>\necho $area<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-862\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-2-1024x733.png\" alt=\"\" width=\"731\" height=\"523\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-2-1024x733.png 1024w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-2-300x215.png 300w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-2-768x550.png 768w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-2-430x308.png 430w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-2.png 1038w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/p>\n<p><strong>\u53d1\u73b0\u9519\u8bef\u65f6\u9000\u51fa\u811a\u672c<\/strong><\/p>\n<p>Bash\u975e\u5e38\u5f3a\u5927\uff0c\u6709\u65f6\u5f53\u51fa\u73b0\u9519\u8bef\u65f6\uff0c\u5b83\u80fd\u591f\u7ee7\u7eed\u8fd0\u884c\u3002\u60a8\u4e0d\u5e94\u8be5\u5141\u8bb8\u8fd9\u6837\u505a\uff0c\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u201cerrexit\u201d\u7684\u7f29\u5199\u9009\u9879\u3002<\/p>\n<p># The script by linuxmi.com<\/p>\n<p>set -e<\/p>\n<p><strong>\u5f53bash\u4f7f\u7528\u672a\u58f0\u660e\u7684\u53d8\u91cf\u65f6\u9000\u51fa\u811a\u672c<\/strong><\/p>\n<p>\u6709\u65f6bash\u53ef\u80fd\u4f1a\u5c1d\u8bd5\u8fd0\u884c\u672a\u58f0\u660e\u7684\u53d8\u91cf\uff0c\u8fd9\u53ef\u80fd\u4f1a\u5bfc\u81f4\u811a\u672c\u6700\u7ec8\u7ed3\u679c\u7684\u5f02\u5e38\u8fd0\u884c\u3002\u8981\u9000\u51fa\u811a\u672c\uff0c\u6211\u4eec\u4f7f\u7528\u7f29\u5199\u7684\u201cnounset\u201d\u9009\u9879\u3002<\/p>\n<p># The script by linuxmi.com<\/p>\n<p>set -u<\/p>\n<p><strong>\u5bf9\u53d8\u91cf\u7684\u5f15\u7528\u5fc5\u987b\u5e26\u6709\u53cc\u5f15\u53f7<\/strong><\/p>\n<p>\u5f53\u6211\u4eec\u5728\u5f15\u7528\u53d8\u91cf\u65f6\u5fc5\u987b\u4f7f\u7528\u53cc\u5f15\u53f7\uff0c\u6211\u4eec\u907f\u514d\u4e86\u5355\u8bcd\u7684\u5212\u5206\u548c\u7a7a\u683c\u3002<\/p>\n<p>#!\/bin\/bash<br \/>\n# The script by linuxmi.com<\/p>\n<p>set -e<\/p>\n<p>set -u<\/p>\n<p>echo &#8220;\u6211\u662fLinux\u8ff7&#8221;<br \/>\necho<br \/>\nnames=&#8221;<a href=\"http:\/\/www.linuxmi.com\">www.linuxmi.com<\/a>\u00a0Linux\u8ff7&#8221;<br \/>\nfor name in $names; do<br \/>\necho &#8220;$name&#8221;<br \/>\ndone<br \/>\necho<\/p>\n<p>echo &#8220;\u53cc\u5f15\u53f7\u8f93\u51fa&#8221;<br \/>\necho<br \/>\nfor name in &#8220;$names&#8221;; do<br \/>\necho &#8220;$name&#8221;<br \/>\ndone<\/p>\n<p>exit 0<\/p>\n<p>\u8f93\u51fa\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-861\" src=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-1-1024x707.png\" alt=\"\" width=\"731\" height=\"505\" srcset=\"https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-1-1024x707.png 1024w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-1-300x207.png 300w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-1-768x530.png 768w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-1-430x297.png 430w, https:\/\/www.linuxmi.com\/wp-content\/uploads\/2020\/06\/bash-1.png 1128w\" sizes=\"auto, (max-width: 731px) 100vw, 731px\" \/><\/p>\n<p><strong>\u4f7f\u7528\u51fd\u6570<\/strong><\/p>\n<p>\u8fd9\u662f\u65b0\u7a0b\u5e8f\u5458\u7684\u4e00\u4e2a\u4e3b\u8981\u5f31\u9879\u3002\u4e60\u60ef\u4f7f\u7528\u51fd\u6570\uff0c\u4f7f\u7528\u65f6\u76f4\u63a5\u8c03\u7528\u51fd\u6570\u540d\uff0c\u8fd9\u6837\u7684\u811a\u672c\u597d\u5904:\u6a21\u5757\u5316\uff0c\u4ee3\u7801\u53ef\u8bfb\u6027\u5f3a\uff0c\u6269\u5c55\u6027\u65b9\u4fbf\uff0c\u66f4\u5bb9\u6613\u9605\u8bfb\u3002<\/p>\n<p>function check_linuxmi(){<br \/>\n\u547d\u4ee4-1;<br \/>\n\u547d\u4ee4-2;<br \/>\n}<\/p>\n<p>\u6216\u8005<\/p>\n<p>check_linuxmi(){\u00a0\u00a0\u00a0\u00a0 \/function \u4e5f\u53ef\u4ee5\u4e0d\u5199<br \/>\n\u547d\u4ee4-1;<br \/>\nc\u547d\u4ee4-2;<br \/>\n}<\/p>\n<p>\u5982\u679c\u60a8\u5728\u4e00\u884c\u4e2d\u751f\u6210\u4ee3\u7801\uff0c\u4e0d\u8981\u5fd8\u8bb0\u5b8c\u6210\u3002<\/p>\n<p>check_linuxmi(){ \u547d\u4ee4-1; \u547d\u4ee4-2; }<\/p>\n<p><strong>\u4f7f\u7528$\u800c\u4e0d\u662f\u53cd\u5f15\u53f7<\/strong><\/p>\n<p>\u8981\u66ff\u6362\u547d\u4ee4\uff0c\u8bf7\u4f7f\u7528$\u7b26\u53f7\u800c\u4e0d\u662f\u53cd\u5f15\u53f7\u3002<\/p>\n<p>user=`echo \u201c$UID\u201d`<br \/>\nuser=$(echo \u201c$UID\u201d)<\/p>\n<p><strong>\u4f7f\u7528\u5927\u5199\u5b57\u6bcd\u8868\u793a\u73af\u5883\u53d8\u91cf<\/strong><\/p>\n<p>\u5bf9\u4e8e\u73af\u5883\u53d8\u91cf\uff0c\u60a8\u5e94\u8be5\u4f7f\u7528\u5927\u5199\u5b57\u6bcd\uff0c\u800c\u5bf9\u4e8e\u81ea\u5b9a\u4e49\u53d8\u91cf\uff0c\u60a8\u5e94\u8be5\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\u3002\u901a\u8fc7\u8fd9\u79cd\u5b9e\u8df5\uff0c\u60a8\u5c06\u907f\u514d\u53d8\u91cf\u4e4b\u95f4\u7684\u8bb8\u591a\u51b2\u7a81\u3002<\/p>\n<p>mi_linux=\u201d$HOME\/linuxmi\/www.linuxmi.com\/linuxmi.sh\u201d<br \/>\nperl \u201c$mi_linux\u201d -h\u00a0 \u201c$1\u201d<\/p>\n<p>\u5728\u9759\u6001\u53d8\u91cf\u4e2d\u4f7f\u7528readonly<\/p>\n<p>\u4e00\u65e6\u5728\u811a\u672c\u4e2d\u5b9a\u4e49\u4e86\u9759\u6001\u53d8\u91cf\uff0c\u5c31\u4e0d\u5e94\u8be5\u4fee\u6539\u5b83\u4eec\uff0c\u6240\u4ee5\u6211\u4eec\u5c06\u5b83\u4eec\u8bbe\u7f6e\u4e3a\u53ea\u8bfb\u6a21\u5f0f\u3002<\/p>\n<p>readonly hostname_file=\u201d\/etc\/hostname\u201d<br \/>\nreadonly localtime_file=\u201d\/etc\/localtime\u201d<br \/>\nreadonly network_file=\u201d\/etc\/network\u201d<\/p>\n<p><strong>\u8c03\u8bd5\u4ee3\u7801<\/strong><\/p>\n<p>\u5982\u679c\u811a\u672c\u53ea\u6709\u51e0\u884c\uff0c\u5219\u4e0d\u9700\u8981\uff0c\u4f46\u662f\u5982\u679c\u60a8\u7f16\u5199\u4e86\u6570\u767e\u884cbash\u811a\u672c\uff0c\u5219\u5fc5\u987b\u5728\u5c06\u5176\u6295\u5165\u751f\u4ea7\u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u8c03\u8bd5\u3002\u5728\u4e0b\u4e00\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u770b\u5230\u5982\u4f55\u8c03\u8bd5bash\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>bash\u811a\u672c\u662f\u5728Linux\u4e0a\u6267\u884c\u548c\u81ea\u52a8\u5316\u4efb\u52a1\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u5b83\u4eec\u5feb\u901f\u3001\u5b89\u5168\u3001\u53ef\u9760\u3002 \u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[75],"class_list":["post-858","post","type-post","status-publish","format-standard","hentry","category-linux","tag-bash"],"aioseo_notices":[],"views":872,"_links":{"self":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/858","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/comments?post=858"}],"version-history":[{"count":3,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/858\/revisions"}],"predecessor-version":[{"id":863,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/posts\/858\/revisions\/863"}],"wp:attachment":[{"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/media?parent=858"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/categories?post=858"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.linuxmi.com\/wp-json\/wp\/v2\/tags?post=858"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}