{"id":730,"date":"2025-10-27T18:42:19","date_gmt":"2025-10-27T10:42:19","guid":{"rendered":"https:\/\/znl.pub\/?p=730"},"modified":"2025-10-27T19:16:06","modified_gmt":"2025-10-27T11:16:06","slug":"%e3%80%90%e8%ae%b0%e5%bd%95%e3%80%91shell%e6%ad%a3%e7%a1%ae%e8%af%bb%e5%8f%96%e6%96%87%e4%bb%b6%e8%b7%af%e5%be%84","status":"publish","type":"post","link":"https:\/\/znl.pub\/?p=730","title":{"rendered":"\u3010\u8bb0\u5f55\u3011shell\u6b63\u786e\u8bfb\u53d6\u6587\u4ef6\u8def\u5f84"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>znl.pub:~# # \u521b\u5efa\u6d4b\u8bd5\u6587\u4ef6\uff08\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff09\nznl.pub:~# mkdir -p \/tmp\/test\nznl.pub:~# touch \"\/tmp\/test\/\u6b63\u5e38\u6587\u4ef6.eml\"\nznl.pub:~# touch \"\/tmp\/test\/\u6587\u4ef6 \u5e26\u7a7a\u683c.eml\"\nznl.pub:~# touch \"\/tmp\/test\/\u6587\u4ef6\\\"\u5e26\u5f15\u53f7.eml\"\nznl.pub:~# touch \"\/tmp\/test\/\u6587\u4ef6\n> \u5e26\u6362\u884c\u7b26.eml\"\nznl.pub:~# touch \"\/tmp\/test\/*.eml\"  # \u5305\u542b\u661f\u53f7\nznl.pub:~# \nznl.pub:~# # \u6d4b\u8bd5\u8bfb\u53d6\nznl.pub:~# count=0\nznl.pub:~# while IFS= read -r -d '' file; do\n>     ((count++))\n>     echo \"\u6b63\u786e\u5904\u7406\u6587\u4ef6 $count: $file\"\n> done &lt; &lt;(find \/tmp\/test -type f -name \"*.eml\" -print0 2>\/dev\/null)\n\u6b63\u786e\u5904\u7406\u6587\u4ef6 1: \/tmp\/test\/\u6b63\u5e38\u6587\u4ef6.eml\n\u6b63\u786e\u5904\u7406\u6587\u4ef6 2: \/tmp\/test\/\u6587\u4ef6 \u5e26\u7a7a\u683c.eml\n\u6b63\u786e\u5904\u7406\u6587\u4ef6 3: \/tmp\/test\/\u6587\u4ef6\"\u5e26\u5f15\u53f7.eml\n\u6b63\u786e\u5904\u7406\u6587\u4ef6 4: \/tmp\/test\/\u6587\u4ef6\n\u5e26\u6362\u884c\u7b26.eml\n\u6b63\u786e\u5904\u7406\u6587\u4ef6 5: \/tmp\/test\/*.eml\nznl.pub:~# echo \"\u603b\u5171\u5904\u7406\u6587\u4ef6\u6570: $count\"\n\u603b\u5171\u5904\u7406\u6587\u4ef6\u6570: 5\nznl.pub:~# cd \/tmp\/test\nznl.pub:\/tmp\/test# find . -name \"*.eml\" | while IFS= read -r file; do\n>     echo \"\u5904\u7406: $file\"  # \u6587\u4ef6\u540d\u5305\u542b\u6362\u884c\u7b26\u65f6\u4f1a\u5206\u5272\u6210\u591a\u884c\n> done\n\u5904\u7406: .\/\u6b63\u5e38\u6587\u4ef6.eml\n\u5904\u7406: .\/\u6587\u4ef6 \u5e26\u7a7a\u683c.eml\n\u5904\u7406: .\/\u6587\u4ef6\"\u5e26\u5f15\u53f7.eml\n\u5904\u7406: .\/\u6587\u4ef6\n\u5904\u7406: \u5e26\u6362\u884c\u7b26.eml\n\u5904\u7406: .\/*.eml\nznl.pub:\/tmp\/test# for file in $(find . -name \"*.eml\"); do\n>     echo \"\u5904\u7406: $file\"  # \u6587\u4ef6\u540d\u5e26\u7a7a\u683c\u65f6\u4f1a\u88ab\u5206\u5272\n> done\n\u5904\u7406: .\/\u6b63\u5e38\u6587\u4ef6.eml\n\u5904\u7406: .\/\u6587\u4ef6\n\u5904\u7406: \u5e26\u7a7a\u683c.eml\n\u5904\u7406: .\/\u6587\u4ef6\"\u5e26\u5f15\u53f7.eml\n\u5904\u7406: .\/\u6587\u4ef6\n\u5904\u7406: \u5e26\u6362\u884c\u7b26.eml\n\u5904\u7406: .\/*.eml\n\u5904\u7406: .\/\u6587\u4ef6\"\u5e26\u5f15\u53f7.eml\n\u5904\u7406: .\/\u6587\u4ef6\n\u5e26\u6362\u884c\u7b26.eml\n\u5904\u7406: .\/\u6587\u4ef6 \u5e26\u7a7a\u683c.eml<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6807\u51c6\u516c\u5f0f &#8211; \u5904\u7406\u4efb\u4f55\u7279\u6b8a\u5b57\u7b26\u90fd\u5b89\u5168\uff08\u8bb0\u4f4f\u8fd9\u4e2a\uff01\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>while IFS= read -r -d '' file; do\n    <em># \u4f60\u7684\u5904\u7406\u903b\u8f91<\/em>\n    echo \"\u5904\u7406\u6587\u4ef6: $file\"\ndone &lt; &lt;(find &#91;\u8def\u5f84] &#91;\u6761\u4ef6] -print0)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u90e8\u5206<\/th><th>\u4f5c\u7528<\/th><th>\u8bb0\u5fc6\u8981\u70b9<\/th><\/tr><\/thead><tbody><tr><td><code>IFS=<\/code><\/td><td>\u9632\u6b62\u5355\u8bcd\u5206\u5272<\/td><td>&#8220;\u6e05\u7a7a\u5b57\u6bb5\u5206\u9694\u7b26&#8221;<\/td><\/tr><tr><td><code>read -r<\/code><\/td><td>\u9632\u6b62\u53cd\u659c\u6760\u8f6c\u4e49<\/td><td>&#8220;raw \u6a21\u5f0f&#8221;<\/td><\/tr><tr><td><code>read -d ''<\/code><\/td><td>\u8bbe\u7f6e\u5206\u9694\u7b26\u4e3a null<\/td><td>&#8220;delimiter \u4e3a\u7a7a = null&#8221;<\/td><\/tr><tr><td><code>&lt; &lt;(command)<\/code><\/td><td>\u8fdb\u7a0b\u66ff\u6362<\/td><td>&#8220;\u628a\u547d\u4ee4\u8f93\u51fa\u5f53\u6587\u4ef6&#8221;\u3002\u9700\u8981\u6ce8\u610f<strong>\u4e24\u4e2a &lt; \u4e4b\u95f4\u6709\u4e2a\u7a7a\u683c<\/strong>\u3002<\/td><\/tr><tr><td><code>find -print0<\/code><\/td><td>\u7528 null \u5206\u9694\u6587\u4ef6\u540d<\/td><td>&#8220;print zero = \u6253\u5370\u96f6 = null&#8221;<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u274c \u9519\u8bef\u65b9\u5f0f\uff08\u5e38\u89c1\u9677\u9631\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. for\u5faa\u73af - \u9047\u5230\u7a7a\u683c\u5c31\u5206\u5272\nfor file in $(find . -name \"*.txt\"); do\n\n# 2. \u7b80\u5355\u7684while - \u9047\u5230\u6362\u884c\u7b26\u5c31\u51fa\u9519  \nfind . -name \"*.txt\" | while read file; do<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6ce8\u610f\u53e6\u4e00\u79cd\u9677\u9631\u5199\u6cd5\uff1a<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>find \"$dir\" -type f -name \"$pattern\" -print0 | while IFS= read -r -d '' file; do\n    echo \"\u5904\u7406: $file\"\ndone<\/code><\/pre>\n\n\n\n<p>\u8fd9\u79cd\u7ba1\u9053\u65b9\u5f0f\u4e5f\u662f\u5b8c\u5168\u6b63\u786e\uff0c\u4f46\u662f\u9700\u8981\u6ce8\u610f\u7ba1\u9053\u7b26\u95ee\u9898\uff1a\u540e\u9762\u7684\u547d\u4ee4\u90fd\u662f\u5728\u5b50\u8fdb\u7a0b\u4e2d\u7684\uff0c\u610f\u5473\u7740\u65e0\u6cd5\u4fee\u6539\u5916\u90e8\u53d8\u91cf\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7279\u6027<\/th><th>\u8fdb\u7a0b\u66ff\u6362\uff08 &lt; &lt;( ) \uff09<\/th><th>\u7ba1\u9053<\/th><\/tr><\/thead><tbody><tr><td>\u53d8\u91cf\u4f5c\u7528\u57df<\/td><td>while \u5faa\u73af\u5728\u5f53\u524dshell\u4e2d<\/td><td>while \u5faa\u73af\u5728\u5b50shell\u4e2d<\/td><\/tr><tr><td>\u53d8\u91cf\u4f20\u9012<\/td><td>\u5faa\u73af\u5185\u53d8\u91cf\u4fee\u6539\u4f1a\u5f71\u54cd\u5916\u90e8<\/td><td>\u5faa\u73af\u5185\u53d8\u91cf\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u5916\u90e8<\/td><\/tr><tr><td>\u8bed\u6cd5\u7b80\u6d01\u6027<\/td><td>\u7a0d\u590d\u6742<\/td><td>\u66f4\u76f4\u89c2\u7b80\u6d01<\/td><\/tr><tr><td>\u517c\u5bb9\u6027<\/td><td>\u9700\u8981 Bash<\/td><td>\u66f4\u901a\u7528<\/td><\/tr><tr><td>\u9002\u7528\u573a\u666f<\/td><td>\u9700\u8981\u4fee\u6539\u53d8\u91cf\u6216\u7edf\u8ba1\u7ed3\u679c<\/td><td>\u7b80\u5355\u5904\u7406\uff0c\u4e0d\u5173\u5fc3\u53d8\u91cf\u4f20\u9012<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u5177\u4f53\u6765\u8bf4\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em># \u65b9\u6cd51\uff1a\u8fdb\u7a0b\u66ff\u6362 - \u8ba1\u6570\u6709\u6548<\/em>\ncount=0\nwhile IFS= read -r -d '' file; do\n    ((count++))\ndone &lt; &lt;(find . -name \"*.eml\" -print0)\necho \"\u627e\u5230 $count \u4e2a\u6587\u4ef6\"  <em># \u6b63\u786e\u663e\u793a\u6570\u91cf<\/em>\n\n<em># \u65b9\u6cd52\uff1a\u7ba1\u9053 - \u8ba1\u6570\u65e0\u6548\uff08\u5e38\u89c1\u9677\u9631\uff01\uff09<\/em>\ncount=0\nfind . -name \"*.eml\" -print0 | while IFS= read -r -d '' file; do\n    ((count++))\ndone\necho \"\u627e\u5230 $count \u4e2a\u6587\u4ef6\"  <em># \u663e\u793a 0\uff01\u56e0\u4e3acount\u5728\u5b50shell\u4e2d\u4fee\u6539<\/em><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u77e5\u8bc6 \u8fdb\u7a0b\u66ff\u6362\uff1a<\/h2>\n\n\n\n<p>\u5b83\u7528&#8221;\u8fdb\u7a0b\u7684\u8f93\u51fa&#8221;\u66ff\u6362\u4e86&#8221;\u6587\u4ef6\u540d&#8221;\u7684\u6982\u5ff5\uff0c<strong>\u628a\u547d\u4ee4\u7684\u8f93\u51fa\u53d8\u6210\u865a\u62df\u6587\u4ef6\uff0c\u7136\u540e\u50cf\u666e\u901a\u6587\u4ef6\u4e00\u6837\u4f7f\u7528<\/strong>\u3002\u67e5\u770b\u8fdb\u7a0b\u66ff\u6362\u7684\u771f\u5b9e\u6548\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em># \u770b\u770b\u8fdb\u7a0b\u66ff\u6362\u521b\u5efa\u4e86\u4ec0\u4e48<\/em>\necho &lt;(ls)\n<em># \u8f93\u51fa\u7c7b\u4f3c\uff1a\/dev\/fd\/63<\/em>\n<em># \u8fd9\u8868\u793a\u521b\u5efa\u4e86\u4e00\u4e2a\u6587\u4ef6\u63cf\u8ff0\u7b26<\/em>\n\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"347\" height=\"38\" src=\"https:\/\/znl.pub\/wp-content\/uploads\/2025\/10\/\u56fe\u7247-1.png\" alt=\"\" class=\"wp-image-734\" srcset=\"https:\/\/znl.pub\/wp-content\/uploads\/2025\/10\/\u56fe\u7247-1.png 347w, https:\/\/znl.pub\/wp-content\/uploads\/2025\/10\/\u56fe\u7247-1-300x33.png 300w\" sizes=\"auto, (max-width: 347px) 100vw, 347px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"586\" height=\"44\" src=\"https:\/\/znl.pub\/wp-content\/uploads\/2025\/10\/\u56fe\u7247.png\" alt=\"\" class=\"wp-image-733\" srcset=\"https:\/\/znl.pub\/wp-content\/uploads\/2025\/10\/\u56fe\u7247.png 586w, https:\/\/znl.pub\/wp-content\/uploads\/2025\/10\/\u56fe\u7247-300x23.png 300w\" sizes=\"auto, (max-width: 586px) 100vw, 586px\" \/><\/figure>\n\n\n\n<p>\u8fdb\u7a0b\u66ff\u6362\u7684\u4e24\u79cd\u5f62\u5f0f\uff1a<\/p>\n\n\n\n<p>\u8f93\u5165\u5f62\u5f0f\uff1a<code>&lt;(...)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em># \u628a\u547d\u4ee4\u8f93\u51fa\u4f5c\u4e3a\u8f93\u5165\u6587\u4ef6<\/em>\ncat &lt;(echo \"hello world\")<\/code><\/pre>\n\n\n\n<p>\u8f93\u51fa\u5f62\u5f0f\uff1a<code>>(...)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># \u628a\u547d\u4ee4\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u547d\u4ee4\u7684\u8f93\u5165 \necho \"hello\" > >(cat)<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6807\u51c6\u516c\u5f0f &#8211; \u5904\u7406\u4efb\u4f55\u7279\u6b8a\u5b57\u7b26\u90fd\u5b89\u5168\uff08\u8bb0\u4f4f\u8fd9\u4e2a\uff01\uff09 \u90e8\u5206 \u4f5c\u7528 \u8bb0\u5fc6\u8981\u70b9 IFS= \u9632\u6b62\u5355\u8bcd\u5206\u5272 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-730","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=730"}],"version-history":[{"count":3,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/730\/revisions"}],"predecessor-version":[{"id":735,"href":"https:\/\/znl.pub\/index.php?rest_route=\/wp\/v2\/posts\/730\/revisions\/735"}],"wp:attachment":[{"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=730"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=730"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/znl.pub\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}