{"id":268487,"date":"2023-03-28T20:04:30","date_gmt":"2023-03-28T12:04:30","guid":{"rendered":"https:\/\/lrxjmw.cn\/btsbldjbyxhj.html"},"modified":"2023-03-28T20:04:30","modified_gmt":"2023-03-28T12:04:30","slug":"btsbldjbyxhj","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/btsbldjbyxhj.html","title":{"rendered":"Bash\u7279\u6b8a\u53d8\u91cf\u7684\u811a\u672c\u8fd0\u884c\u73af\u5883\u6307\u5357-\u4e0a\u6d77\u6021\u5065\u533b\u5b66"},"content":{"rendered":"
Bash\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u608d\u7684Shelllinux\u7528\u6237\u73af\u5883\u53d8\u91cf<\/a><\/strong>\uff0c\u63d0\u4f9b\u4e86\u5404\u7c7b\u7279\u6b8a\u53d8\u91cf\uff0c\u53ef\u4ee5\u7528\u4e8e\u64cd\u4f5c\u548c\u63a7\u5236\u811a\u672c\u7684\u884c\u4e3a\u3002\u8fd9\u79cd\u53d8\u91cf\u63d0\u4f9b\u4e86\u6709\u5173\u811a\u672c\u8fd0\u884c\u73af\u5883\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u5305\u62ec\u547d\u4ee4<\/a>\u884c\u53c2\u6570\u3001\u5f53\u524d\u8fdb\u7a0bID\u548c\u5148\u524d\u6267\u884c\u547d\u4ee4\u7684\u72b6\u6001\u3002<\/p>\n \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u63d0\u4f9b\u6240\u6709Bash\u7279\u6b8a\u53d8\u91cf\u7684\u6df1\u5165\u624b\u518c\uff0c\u5305\u62ec\u5b83\u4eec\u7684\u4f7f\u7528\u793a\u4f8b\u548c\u5e38\u89c1\u7684\u95ee\u9898\u9632\u6b62\u6280\u5de7\u3002<\/p>\n \u201c$0\u201d\u2013\u6b63\u5728\u6267\u884c\u7684\u811a\u672c\u7684\u540d\u79f0\u3002\u201d$1-$9\u201d\u2013\u524d\u4e5d\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u3002\u201c$#\u201d\u2013\u547d\u4ee4\u884c\u53c2\u6570\u7684\u6570\u76ee\u3002\u201d$*\u201c\u2013\u6240\u6709\u547d\u4ee4\u884c\u53c2\u6570\u4f5c\u4e3a\u5355\u4e2a\u5b57\u7b26\u4e32\u3002\u201d$@\u201d\u2013\u6240\u6709\u547d\u4ee4\u884c\u53c2\u6570\u4f5c\u4e3a\u4e00\u4e2a\u94fe\u8868\u3002\u201c$\uff1f\u201d\u2013\u4e0a\u6b21\u6267\u884c\u7684\u547d\u4ee4\u7684\u9000\u51fa\u72b6\u6001\u3002\u201d$$\u201c\u2013\u5f53\u524dshell<\/a>\u7684\u8fdb\u7a0bID\u3002\u201d$\uff01\u201c\u2013\u6700\u540e\u4e00\u4e2a\u540e\u53f0\u547d\u4ee4\u7684\u8fdb\u7a0bID\u3002<\/p>\n \u8ba9\u6211\u4eec\u8be6\u5c3d\u8ba8\u8bba\u7279\u6b8a\u53d8\u91cf\u5e76\u63d0\u4f9b\u793a\u4f8b\u3002<\/p>\n $0\u2013\u6b63\u5728\u6267\u884c\u7684\u811a\u672c\u7684\u540d\u79f0<\/p>\n \u5728Bash\u4e2d\uff0c$0\u662f\u4e00\u4e2a\u7279\u6b8a\u53c2\u6570\uff0c\u5b83\u4fdd\u5b58\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u811a\u672c\u6216Shell\u7684\u540d\u79f0\u3002\u5b83\u4e5f\u88ab\u79f0\u4e3a\u811a\u672c\u7684\u201c\u540d\u79f0\u201d\u6216\u201c\u96f6\u53f7\u53c2\u6570\u201d\u3002<\/p>\n \n <\/p>\n \u6bd4\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201c\u201d\u7684\u811a\u672clinux\u4f0a\u7538\u56ed\uff0c\u60a8\u60f3\u4ece\u4efb\u4f55\u76ee\u5f55\u8fd0\u884c\u5b83\u3002\u8fd9\u4e48\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$0\u53d8\u91cf\u6765\u786e\u5b9a\u6b63\u5728\u6267\u884c\u7684\u811a\u672c\u7684\u540d\u79f0\uff1a<\/p>\n \n $1\uff0c$2\uff0c\u2026\uff0c$9\u2013\u547d\u4ee4\u884c\u53c2\u6570<\/p>\n $1\uff0c$2\uff0c\u2026\uff0c$9\u53d8\u91cf\u5305\u542b\u4f20\u9012\u7ed9\u811a\u672c\u7684\u524d\u4e5d\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u3002\u8fd9\u79cd\u53d8\u91cf\u5bf9\u4e8e\u521b\u5efa\u63a5\u53d7\u7528\u6237\u8f93\u5165\u7684shell\u811a\u672c\u7279\u522b\u6709\u7528\u3002<\/p>\n \u6bd4\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201cgreet.sh\u201d\u7684\u811a\u672c\uff0c\u5b83\u5c06\u4e00\u4e2a\u540d\u53eb\u505a\u4e3a\u5176\u7b2c\u4e00\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$1\u53d8\u91cf\u6765\u68c0\u7d22\u540d\u79f0\uff0c\u4e4b\u540e\u5728\u811a\u672c\u7684\u8f93\u51fa\u4e2d\u4f7f\u7528\u5b83\u3002<\/p>\n \n \u5047\u5982\u811a\u672c\u987b\u8981\u8bbf\u95ee\u8d85\u8fc7\u4e5d\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528${10}\u3001${11}linux\u7528\u6237\u73af\u5883\u53d8\u91cf<\/strong>\uff0c\u2026\uff0c${N}\u53d8\u91cf\u6765\u68c0\u7d22\u5b83\u4eec\u3002\u8fd9\u79cd\u53d8\u91cf\u53ef\u4ee5\u4e0eshift\u547d\u4ee4\u4e00\u8d77\u4f7f\u7528\uff0c\u4ee5\u6279\u5904\u7406\u65b9\u6cd5\u5904\u7406\u547d\u4ee4\u884c\u53c2\u6570\u3002\u786e\u4fdd\u53d8\u91cf\u7528{}\u62ec\u4e0a\u53bb\u3002<\/p>\n $#\u2013\u547d\u4ee4\u884c\u53c2\u6570\u7684\u6570\u76ee<\/p>\n $#\u53d8\u91cf\u5305\u542b\u4f20\u9012\u7ed9\u811a\u672c\u7684\u547d\u4ee4\u884c\u53c2\u6570\u6570\u76ee\u3002\u6b64\u53d8\u91cf\u5bf9\u4e8e\u521b\u5efa\u9a8c\u8bc1\u7528\u6237\u8f93\u5165\u7684shell\u811a\u672c\u7279\u522b\u6709\u7528\u3002<\/p>\n \u6bd4\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201clinuxmi.sh\u201d\u7684\u811a\u672c\uff0c\u987b\u8981\u4e24\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$#\u53d8\u91cf\u6765\u786e\u4fdd\u63d0\u4f9b\u4e86\u6b63\u786e\u6570\u76ee\u7684\u53c2\u6570\u3002<\/p>\n \n $*\u2013\u5c06\u6240\u6709\u547d\u4ee4\u884c\u53c2\u6570\u4f5c\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32<\/p>\n $*\u53d8\u91cf\u5305\u542b\u4f5c\u4e3a\u5355\u4e2a\u5b57\u7b26\u4e32\u4f20\u9012\u7ed9\u811a\u672c\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c2\u6570\u3002\u8be5\u53d8\u91cf\u5bf9\u4e8e\u987b\u8981\u64cd\u4f5c\u6574\u4e2a\u547d\u4ee4\u884c\u5b57\u7b26\u4e32\u7684Shell\u811a\u672c\u7279\u522b\u6709\u7528\u3002<\/p>\n \u6bd4\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201cjoin.sh\u201d\u7684\u811a\u672c\uff0c\u7528\u4e8e\u8054\u63a5\u4f5c\u4e3a\u547d\u4ee4\u884c\u53c2\u6570\u63d0\u4f9b\u7684\u4e24\u4e2a\u5b57\u7b26\u4e32\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$*\u53d8\u91cf\u6765\u8054\u63a5\u8fd9\u79cd\u5b57\u7b26\u4e32\u3002<\/p>\n \n $@\u2013\u5c06\u6240\u6709\u547d\u4ee4\u884c\u53c2\u6570\u4f5c\u4e3a\u5f62\u53c2<\/p>\n $@\u53d8\u91cf\u5305\u542b\u4f5c\u4e3a\u5f62\u53c2\u4f20\u9012\u7ed9\u811a\u672c\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c2\u6570\u3002\u8be5\u53d8\u91cf\u5bf9\u4e8e\u987b\u8981\u64cd\u4f5c\u5355\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u7684Shell\u811a\u672c\u7279\u522b\u6709\u7528\u3002<\/p>\n \u6bd4\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201clist.sh\u201d\u7684\u811a\u672c\uff0c\u7528\u4e8e\u5217\u4e3e\u4f5c\u4e3a\u547d\u4ee4\u884c\u53c2\u6570\u63d0\u4f9b\u7684\u76ee\u5f55\u4e2d\u7684\u6240\u6709\u6587\u4ef6\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$@\u53d8\u91cf\u6765\u8fed\u4ee3\u6bcf\u4f4d\u76ee\u5f55\u540d\u79f0\u5e76\u5217\u4e3e\u8be5\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002<\/p>\n \n $?\u2013\u6700\u8fd1\u6267\u884c\u547d\u4ee4\u7684\u9000\u51fa\u72b6\u6001<\/p>\n $?\u53d8\u91cf\u5305\u542b\u8fd1\u6765\u6267\u884c\u547d\u4ee4\u7684\u9000\u51fa\u72b6\u6001\u3002\u8be5\u53d8\u91cf\u5bf9\u4e8e\u987b\u8981\u5904\u7406\u9519\u8bef\u6216\u6309\u7167\u547d\u4ee4\u7684\u6210\u529f\u6216\u5931\u8d25\u91c7\u53d6\u4e0d\u540c\u64cd\u4f5c\u7684Shell\u811a\u672c\u7279\u522b\u6709\u7528\u3002<\/p>\n \u6bd4\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201ccreate-file.sh\u201d\u7684\u811a\u672c\uff0c\u7528\u4e8e\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u5e76\u8fd4\u56de\u8868\u793a\u6210\u529f\u6216\u5931\u8d25\u7684\u9000\u51fa\u72b6\u6001\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$?\u53d8\u91cf\u6765\u68c0\u6d4b\u9000\u51fa\u72b6\u6001\u5e76\u91c7\u53d6\u9002\u5f53\u7684\u64cd\u4f5c\u3002<\/p>\n \n $$\u53d8\u91cf\u5305\u542b\u5f53\u524d\u811a\u672c\u7684\u8fdb\u7a0bID<\/p>\n \u8be5\u53d8\u91cf\u5bf9\u4e8e\u987b\u8981\u7ba1\u7406\u591a\u4e2a\u8fdb\u7a0b\u6216\u521b\u5efa\u60df\u4e00\u6587\u4ef6\u540d\u7684Shell\u811a\u672c\u7279\u522b\u6709\u7528\u3002\u8bf8\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201clog.sh\u201d\u7684\u811a\u672c\uff0c\u7528\u4e8e\u8bb0\u5f55\u4fe1\u606f\u5230\u4e00\u4e2a\u57fa\u4e8e\u8fdb\u7a0bID\u7684\u60df\u4e00\u6587\u4ef6\u540d\u7684\u6587\u4ef6\u4e2d\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$$\u53d8\u91cf\u6765\u4e16\u6210\u4e00\u4e2a\u60df\u4e00\u7684\u6587\u4ef6\u540d\u3002<\/p>\n \n $!\u2013\u6700\u8fd1\u540e\u53f0\u547d\u4ee4\u7684\u8fdb\u7a0bID<\/p>\n $!\u53d8\u91cf\u5305\u542b\u811a\u672c\u6267\u884c\u7684\u8fd1\u6765\u540e\u53f0\u547d\u4ee4\u7684\u8fdb\u7a0bID\u3002\u8be5\u53d8\u91cf\u5bf9\u4e8e\u987b\u8981\u7ba1\u7406\u591a\u4e2a\u8fdb\u7a0b\u6216\u76d1\u89c6\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u547d\u4ee4\u7684Shell\u811a\u672c\u7279\u522b\u6709\u7528\u3002<\/p>\n \u6bd4\u5982\uff0c\u5047\u5b9a\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a\u201c\u201d\u7684\u811a\u672c\uff0c\u7528\u4e8e\u5728\u540e\u53f0\u8fd0\u884c\u4e00\u4e2a\u547d\u4ee4\u5e76\u8bb0\u5f55\u5176\u8fdb\u5ea6\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528$!\u53d8\u91cf\u6765\u76d1\u89c6\u547d\u4ee4\u7684\u8fdb\u5ea6\u3002<\/p>\n \n \u603b\u7ed3<\/p>\n Bash\u7279\u6b8a\u53d8\u91cf\u63d0\u4f9b\u4e86\u6709\u5173\u811a\u672c\u8fd0\u884c\u73af\u5883\u7684\u91cd\u8981\u4fe1\u606f\u3002\u8fd9\u79cd\u53d8\u91cf\u4f7f\u60a8\u80fd\u5426\u521b\u5efa\u6108\u53d1\u7075\u6d3b\u3001\u5065\u58ee\u548c\u4e0d\u5bb9\u6613\u51fa\u73b0\u5f02\u5e38\u6216\u5d29\u6e83\u7684Shell\u811a\u672c\u3002\u901a\u8fc7\u628a\u63e1\u8fd9\u79cd\u53d8\u91cf\u7684\u7528\u6cd5linux\u57f9\u8bad\u73ed\uff0c\u60a8\u53ef\u4ee5\u5c06\u81ea\u5df1\u7684Shell\u811a\u672c\u6280\u80fd\u63d0\u9ad8\u5230\u66f4\u9ad8\u7684\u6c34\u5e73\u3002<\/p>\n","protected":false},"excerpt":{"rendered":" Shell\uff0c\u63d0\u4f9b\u4e86\u5404\u79cd\u7279\u6b8a\u53d8\u91cf\uff0c\u53ef\u4ee5\u7528\u4e8e\u64cd\u4f5c\u548c\u63a7\u5236\u811a\u672c\u7684\u884c\u4e3a\u3002\u662f\u4e00\u4e2a\u7279\u6b8a\u53c2\u6570\uff0c\u5b83\u4fdd\u5b58\u5f53\u524d\u6b63\u5728\u6267\u884c\u7684\u811a\u672c\u6216Shell\u7684\u540d\u79f0\u3002\u53d8\u91cf\u5305\u542b\u4f20\u9012\u7ed9\u811a\u672c\u7684\u524d\u4e5d\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u3002\u53d8\u91cf\u5305\u542b\u4f20\u9012\u7ed9\u811a\u672c\u7684\u547d\u4ee4\u884c\u53c2\u6570\u6570\u91cf\u3002\u53d8\u91cf\u5305\u542b\u4f5c\u4e3a\u6570\u7ec4\u4f20\u9012\u7ed9\u811a\u672c\u7684\u6240\u6709\u547d\u4ee4\u884c\u53c2\u6570\u3002\u8be5\u53d8\u91cf\u5bf9\u4e8e\u9700\u8981\u64cd\u4f5c\u5355\u4e2a\u547d\u4ee4\u884c\u53c2\u6570\u7684Shell\u811a\u672c\u975e\u5e38\u6709\u7528\u3002\u53d8\u91cf\u5305\u542b\u5f53\u524d\u811a\u672c\u7684\u8fdb\u7a0bID\u7279\u6b8a\u53d8\u91cf\u63d0\u4f9b\u4e86\u6709\u5173\u811a\u672c\u8fd0\u884c\u73af\u5883\u7684\u91cd\u8981\u4fe1\u606f\u3002<\/p>\n","protected":false},"author":1,"featured_media":268488,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[988],"tags":[999],"class_list":["post-268487","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tougao","tag-999"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/268487","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=268487"}],"version-history":[{"count":0,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/268487\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/268488"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=268487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=268487"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=268487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}#!\/bin\/bash<\/a>\n# Linux\u8ff7 www.linuxmi.com\necho \"\u5f53\u524d\u8fd0\u884c\u7684\u811a\u672c\u662f: $0\"<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\nSCRIPT_DIR=\"$( cd \"$( dirname \"${BASH_SOURCE[0]}\" )\" && pwd )\"\necho \"\u811a\u672c\u6b63\u5728\u4ece $SCRIPT_DIR \u8fd0\u884c\"<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\necho \"Hello, $1!\"<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\nif [[ $# -ne 2 ]]\nthen\n echo \"Usage: linuxmi.sh [username] [password]\"\n exit 1\nfi<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\njoined=\"$*<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\nfor directory in \"$@\"\ndo\n echo \"\u6b63\u5728\u5217\u51fa\u4e2d\u7684\u6587\u4ef6 $directory:\"\n ls -l $directory\ndone<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\ntouch linuximi.txt\nif [[ $? -eq 0 ]]\nthen\n echo \"\u6587\u4ef6\u521b\u5efa\u6210\u529f\"\nelse\n echo \"\u521b\u5efa\u6587\u4ef6\u65f6\u51fa\u9519\"\nfi<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\nLOG_FILE=\"log_$$.txt\"\necho \"\u6b63\u5728\u8bb0\u5f55\u5230\u6587\u4ef6 $LOG_FILE\"<\/code><\/pre>\n<\/p>\n
#!\/bin\/bash\n# Linux\u8ff7 www.linuxmi.com\nmycommand &\npid=$!\nwhile ps -p $pid >\/dev\/null; do\n echo \"\u547d\u4ee4\u4ecd\u5728\u8fd0\u884c\"\n sleep 1\ndone\necho \"\u547d\u4ee4\u5df2\u5b8c\u6210\"<\/code><\/pre>\n<\/p>\n