{"id":191112,"date":"2020-05-25T08:08:06","date_gmt":"2020-05-25T00:08:06","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=191112"},"modified":"2020-05-17T16:10:56","modified_gmt":"2020-05-17T08:10:56","slug":"use-shell-script","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/use-shell-script.html","title":{"rendered":"\u5229\u7528Shell\u811a\u672c\u8bfb\u53d6\u6587\u4ef6\u4e2d\u6bcf\u4e00\u884c"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\uff0cShell\u4fd7\u79f0\u58f3(\u7528\u6765\u533a\u522b\u4e8e\u6838)\uff0c\u662f\u6307\"\u4e3a\u4f7f\u7528\u8005\u63d0\u4f9b\u64cd\u4f5c\u754c\u9762\"\u7684\u8f6f\u4ef6(\u547d\u4ee4\u89e3\u6790\u5668)\u3002\u5b83\u7c7b\u4f3c\u4e8eDOS\u4e0b\u7684command.com\u548c\u540e\u6765\u7684cmd.exe\u3002\u5b83\u63a5\u6536\u7528\u6237\u547d\u4ee4\uff0c\u7136\u540e\u8c03\u7528\u76f8\u5e94\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u540c\u65f6\u5b83\u53c8\u662f\u4e00\u79cd\u7a0b\u5e8f\u8bbe\u8ba1\u8bed\u8a00\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5047\u8bbe\u8bfb\u53d6\u7684\u6587\u4ef6\u4e3a\u5f53\u671f\u76ee\u5f55\u4e0b\u7684 test.txt \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n

Google \r\nRunoob\r\nTaobao<\/pre>\n

\u5b9e\u4f8b 1<\/strong><\/p>\n

#!\/bin\/bash\r\n\r\nwhile read line\r\ndo\r\n    echo $line\r\ndone < test.txt<\/pre>\n

\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n

Google\r\nRunoob\r\nTaobao<\/pre>\n

\u5b9e\u4f8b 2<\/strong><\/p>\n

#!\/bin\/bash\r\n\r\ncat test.txt | while read line\r\ndo\r\n    echo $line\r\ndone<\/pre>\n

\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n

Google\r\nRunoob\r\nTaobao<\/pre>\n

\u5b9e\u4f8b 3<\/strong><\/p>\n

for line in `cat  test.txt`\r\ndo\r\n    echo $line\r\ndone<\/pre>\n

\u6267\u884c\u8f93\u51fa\u7ed3\u679c\u4e3a\uff1a<\/p>\n

Google\r\nRunoob\r\nTaobao<\/pre>\n

for \u9010\u884c\u8bfb\u548c while \u9010\u884c\u8bfb\u662f\u6709\u533a\u522b\u7684\uff0c\u5982:<\/p>\n

\r\n$ cat<\/span> test.txt
\r\nGoogle
\r\nRunoob
\r\nTaobao
\r\n$ cat<\/span> test.txt |<\/span> while<\/span> read<\/span> line; do<\/span> echo<\/span> $line<\/span>; done<\/span>
\r\nGoogle
\r\nRunoob
\r\nTaobao
\r\n$ for<\/span> line in<\/span> $(<\/span><<\/span>test.txt)<\/span>; do<\/span> echo<\/span> $line<\/span>; done<\/span>
\r\nGoogle
\r\nRunoob
\r\nTaobao
<\/div><\/pre>\n","protected":false},"excerpt":{"rendered":"

\u5047\u8bbe\u8bfb\u53d6\u7684\u6587\u4ef6\u4e3a\u5f53\u671f\u76ee\u5f55\u4e0b\u7684 test.txt \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a Google Runoob Taobao \u5b9e […]<\/p>\n","protected":false},"author":1481,"featured_media":191114,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-191112","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191112","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\/1481"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=191112"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191112\/revisions"}],"predecessor-version":[{"id":191118,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191112\/revisions\/191118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/191114"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=191112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=191112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=191112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}