{"id":619,"date":"2023-01-13T12:07:50","date_gmt":"2023-01-13T04:07:50","guid":{"rendered":"https:\/\/julyclyde.org\/?p=619"},"modified":"2023-01-16T14:25:54","modified_gmt":"2023-01-16T06:25:54","slug":"gnu%e5%92%8cbsd%e7%89%88%e6%9c%ac%e7%9a%84xargs-%e5%88%86%e9%9a%94%e7%ac%a6%e4%b8%8d%e5%90%8c","status":"publish","type":"post","link":"https:\/\/julyclyde.org\/?p=619","title":{"rendered":"GNU\u548cBSD\u7248\u672c\u7684xargs \u5206\u9694\u7b26\u4e0d\u540c"},"content":{"rendered":"\n<p>\u4f8b\u5b50\uff1a<br><code>list=\"a b c d e\"; echo $list |xargs -n1 -I{} echo begin {} end<\/code><\/p>\n\n\n\n<p>\u5728Mac\u4e0a\u6267\u884c\u7ed3\u679c\uff1a<br>begin a end<br>begin b end<br>begin c end<br>begin d end<br>begin e end<\/p>\n\n\n\n<p>\u5728Linux\u4e0a\u6267\u884c\u7ed3\u679c\uff1a<br>begin a b c d e end<\/p>\n\n\n\n<p>\u6211\u8fd9\u91cc\u7684\u9700\u6c42\u662f\u6709\u4e00\u5806\u8f93\u5165\uff0c\u8981\u5206\u522b\u4ee5\u5176\u4e3a\u53c2\u6570\uff0c\u6267\u884c\u4e00\u4e9b\u547d\u4ee4\uff0c\u65e0\u8bba\u662f\u5426\u6210\u529f\u90fd\u8981\u5bf9\u6240<br>\u6709\u76ee\u6807\u6267\u884c\uff0c\u6240\u4ee5<br>1 \u201c\u4e00\u4e9b\u547d\u4ee4\u201d\u6211\u9009\u7528shell function\u6765\u5b9e\u73b0\uff0c\u5728\u5176\u4e2d\u8bfb\u4e86$1\u4f5c\u4e3a\u672c\u6b21\u5904\u7406\u7684\u76ee\u6807<br>2 \u201c\u6240\u6709\u76ee\u6807\u201d\u6211\u9009\u7528xargs\uff1b\u5982\u679c\u9009Parallel\u8fd8\u5f97\u989d\u5916\u5b89\u88c5<\/p>\n\n\n\n<p>\u7ed3\u679c\u53d1\u73b0xargs\u5728\u5207\u5206\u201c\u4ee5\u7a7a\u683c\u4e3a\u5206\u9694\u7b26\u201d\u7684\u5b57\u7b26\u4e32\u7684\u65f6\u5019\uff0cGNU\u7248\u672c\u9ed8\u8ba4\u4e0d\u5207\u5206\uff0c\u7ed3\u679c\u628a<br>\u6574\u4e2a\u201c\u542b\u7a7a\u683c\u5206\u9694\u7b26\u7684\u5b57\u7b26\u4e32\u201d\u4f20\u7ed9\u51fd\u6570\uff0c\u6267\u884c\u4e86\u4e00\u6b21\uff0c\u800c\u51fd\u6570\u91cc\u53c8\u9009\u4e86$1\u4f5c\u4e3a\u672c\u6b21\u6267\u884c<br>\u76ee\u6807\uff0c\u5176\u7efc\u5408\u7ed3\u679c\u5c31\u662f\u53ea\u5bf9\u5217\u8868\u4e2d\u7b2c\u4e00\u4e2a\u76ee\u6807\u6267\u884c\u4e86\u4e00\u904d<\/p>\n\n\n\n<p>\u66f4\u60e8\u7684\u662f\u6211\u5bf9\u6bd4\u7684\u65f6\u5019\u662f\u5728Mac\u4e0a\u505a\u7684\u5bf9\u6bd4\uff0c\u600e\u4e48\u770b\u600e\u4e48\u987a\u773c\u2026\u2026<\/p>\n\n\n\n<p>\u6700\u540e\u8bf7\u6559\u540c\u4e8b\uff0c\u7528xargs\u7684-d\u53c2\u6570\u89e3\u51b3\u7684<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   This  manual page documents the GNU version of xargs.  xargs reads items from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines<\/code><\/pre>\n\n\n\n<p>GNU xargs\u7684manpage\u8bf4\u652f\u6301blanks \u6309\u8bf4\u7a7a\u683c\u4e5f\u5e94\u8be5\u53ef\u4ee5\u554a\u2026\u2026<br>xargs.c\u7684read_line\u51fd\u6570\u91cc\uff1a<\/p>\n\n\n\n<p><code>&nbsp;&nbsp;893&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/* POSIX: In the POSIX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;<br>&nbsp;&nbsp;909&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p = linebuf;&nbsp;<br>&nbsp;&nbsp;910&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; state = SPACE;&nbsp;<br>&nbsp;&nbsp;911&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; first = false;&nbsp;<br>&nbsp;&nbsp;912&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; continue;&nbsp;<br>&nbsp;&nbsp;913&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }&nbsp;<\/code><\/p>\n\n\n\n<p>\u8fd9\u4e00\u6bb5\u72b6\u6001\u673a\u4ee3\u7801\u5e94\u8be5\u662f\u201c\u4e4b\u524d\u8bfb\u5230\u4e86\u666e\u901a\u5b57\u7b26\uff0c\u8fd9\u6b21\u8bfb\u5230\u4e86\u7a7a\u683c\u201d\u7684\u5904\u7406\uff0c\u8fd9\u65f6\u5019\u5e94\u8be5\u628a\u5df2\u7ecf\u8bfb\u5230\u7684\u8fd9\u4e00\u6bb5\u4f5c\u4e3a\u4e00\u4e2a\u53c2\u6570\u52a0\u5230\u5217\u8868\u91cc\u53bb&nbsp;<br><\/p>\n\n\n\n<p>\u770b\u5b83\u7684\u5224\u65ad\u6761\u4ef6if (!bc_ctl.replace_pat &amp;&amp; ISBLANK (c))&nbsp;<br>\u5176\u5b9e\u662f\u8981\u6c42\u6ca1\u7528-i\/-I\u53c2\u6570\uff0c\u4e14\u672c\u6b21\u8bfb\u5230\u7684\u5b57\u7b26\u4e3a\u7a7a\u767d<\/p>\n\n\n\n<p>\u9a8c\u8bc1\u4e00\u4e0b\uff0c\u53bb\u6389-i\u4e4b\u540e\uff1a<\/p>\n\n\n\n<p>echo a b c d e |xargs -n1\u00a0\u00a0echo begin {} end\u00a0<br>\u8fd0\u884c\u7ed3\u679c\u5c31\u51e0\u4e4e\u6b63\u786e\u4e86\u3002\u867d\u7136\u4e27\u5931\u4e86\u4f7f\u7528\u5360\u4f4d\u7b26\u7684\u80fd\u529b\uff0c\u4f46\u81f3\u5c11\u5b83\u786e\u5b9e\u6309\u7167\u7a7a\u683c\u8fdb\u884c\u5206\u5272\u4e86\u00a0<br>begin {} end a\u00a0<br>begin {} end b\u00a0<br>begin {} end c\u00a0<br>begin {} end d\u00a0<br>begin {} end e\u00a0<br>\u00a0\u00a0<br>\u6211\u89c9\u5f97\u8fd9\u4e2a\u5224\u65ad\u6761\u4ef6\u5c31\u662f\u4e2abug\u3002\u4f46\u662f\u6709\u7f51\u53cb\u6307\u51fa\uff1a\u6309\u7167POSIX\u6807\u51c6\u3001GNU xargs\u7684\u6587\u6863\uff0c\u5f00\u542f-I\u5c31\u662f\u5f3a\u5236\u4e00\u6574\u884c\u7684\uff0c\u6211\u7684\u7528\u6cd5\u4e0d\u6e05\u771f\u3002\u5bf9\u6b64\u6211\u53ea\u80fd\u8bf4\uff1a\u6ee1\u8db3\u6807\u51c6\u4f46\u662f\u4e0d\u6ee1\u8db3\u9700\u6c42\u554a\uff0c\u4e3a\u4ec0\u4e48\u8f93\u51fa\u7aef\u7684\u53c2\u6570\u4f1a\u5f71\u54cd\u8f93\u5165\u7aef\u7684\u884c\u4e3a\u5462\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f8b\u5b50\uff1alist=&#8221;a b c d e&#8221;; echo $list |xargs -n1 -I{} echo begin {} end \u5728Mac\u4e0a\u6267\u884c\u7ed3\u679c\uff1abegin a endbegin b endbegin c endbegin d endbegin e end \u5728Linux\u4e0a\u6267\u884c\u7ed3\u679c\uff1abegin a b c d e end \u6211\u8fd9\u91cc\u7684\u9700\u6c42\u662f\u6709\u4e00\u5806\u8f93\u5165\uff0c\u8981\u5206\u522b\u4ee5\u5176\u4e3a\u53c2\u6570\uff0c\u6267\u884c\u4e00\u4e9b\u547d\u4ee4\uff0c\u65e0\u8bba\u662f\u5426\u6210\u529f\u90fd\u8981\u5bf9\u6240\u6709\u76ee\u6807\u6267\u884c\uff0c\u6240\u4ee51 \u201c\u4e00\u4e9b\u547d\u4ee4\u201d\u6211\u9009\u7528shell function\u6765\u5b9e\u73b0\uff0c\u5728\u5176\u4e2d\u8bfb\u4e86$1\u4f5c\u4e3a\u672c\u6b21\u5904\u7406\u7684\u76ee\u68072 \u201c\u6240\u6709\u76ee\u6807\u201d\u6211\u9009\u7528xargs\uff1b\u5982\u679c\u9009Parallel\u8fd8\u5f97\u989d\u5916\u5b89\u88c5 \u7ed3\u679c\u53d1\u73b0xargs\u5728\u5207\u5206\u201c\u4ee5\u7a7a\u683c\u4e3a\u5206\u9694\u7b26\u201d\u7684\u5b57\u7b26\u4e32\u7684\u65f6\u5019\uff0cGNU\u7248\u672c\u9ed8\u8ba4\u4e0d\u5207\u5206\uff0c\u7ed3\u679c\u628a\u6574\u4e2a\u201c\u542b\u7a7a\u683c\u5206\u9694\u7b26\u7684\u5b57\u7b26\u4e32\u201d\u4f20\u7ed9\u51fd\u6570\uff0c\u6267\u884c\u4e86\u4e00\u6b21\uff0c\u800c\u51fd\u6570\u91cc\u53c8\u9009\u4e86$1\u4f5c\u4e3a\u672c\u6b21\u6267\u884c\u76ee\u6807\uff0c\u5176\u7efc\u5408\u7ed3\u679c\u5c31\u662f\u53ea\u5bf9\u5217\u8868\u4e2d\u7b2c\u4e00\u4e2a\u76ee\u6807\u6267\u884c\u4e86\u4e00\u904d \u66f4\u60e8\u7684\u662f\u6211\u5bf9\u6bd4\u7684\u65f6\u5019\u662f\u5728Mac\u4e0a\u505a\u7684\u5bf9\u6bd4\uff0c\u600e\u4e48\u770b\u600e\u4e48\u987a\u773c\u2026\u2026 \u6700\u540e\u8bf7\u6559\u540c\u4e8b\uff0c\u7528xargs\u7684-d\u53c2\u6570\u89e3\u51b3\u7684 GNU &hellip; <a href=\"https:\/\/julyclyde.org\/?p=619\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-619","post","type-post","status-publish","format-standard","hentry","category-default","tag-linux"],"_links":{"self":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/posts\/619","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=619"}],"version-history":[{"count":0,"href":"https:\/\/julyclyde.org\/index.php?rest_route=\/wp\/v2\/posts\/619\/revisions"}],"wp:attachment":[{"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/julyclyde.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}