{"id":238,"date":"2007-04-18T08:44:18","date_gmt":"2007-04-18T06:44:18","guid":{"rendered":"http:\/\/www.lucas-nussbaum.net\/blog\/?p=238"},"modified":"2007-04-18T08:44:18","modified_gmt":"2007-04-18T06:44:18","slug":"bash-is-weird","status":"publish","type":"post","link":"https:\/\/www.lucas-nussbaum.net\/blog\/?p=238","title":{"rendered":"Bash is weird."},"content":{"rendered":"<p>Consider the following command:<br \/>\n<code>echo <(cat \/etc\/{motd,passwd})<\/code><\/p>\n<p>(you can replace \"echo\" with any command that takes one file as argument and cannot take it as stdin)<\/p>\n<p>It's obvious that the goal is to expand this to:<br \/>\n<code>echo <(cat \/etc\/motd \/etc\/passwd)<\/code><\/p>\n<p>Then to:<br \/>\n<code>echo \/dev\/fd\/63<\/code><\/p>\n<p>However, it doesn't work like this:<br \/>\n<code>$ echo <(cat \/etc\/{motd,passwd})\n++ cat \/etc\/motd\n++ cat \/etc\/passwd\n+ echo \/dev\/fd\/63 \/dev\/fd\/62\n\/dev\/fd\/63 \/dev\/fd\/62<\/code><\/p>\n<p>But bash doesn't work like this. Brace expansion is done first, but inside parameters of the command (that is, <code><(cat \/etc\/{motd,passwd})<\/code>) not <b>words<\/b>. So when <code><(cat \/etc\/{motd,passwd})<\/code> is expanded, the prefix is <code><(cat \/etc\/<\/code>, the suffix is \")\", so it's expanded to <code><(cat \/etc\/motd) <(cat \/etc\/passwd)<\/code>.<\/p>\n<p>After reporting a bug about that, Chet Ramey gave me the correct way to reach the initial goal:<br \/>\n<code>cat <(eval cat \/etc\/\\{passwd,motd})<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Consider the following command: echo<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"0","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,13,12,7],"tags":[],"class_list":["post-238","post","type-post","status-publish","format-standard","hentry","category-debianubuntu","category-planetdebian","category-planetubuntu","category-technology"],"_links":{"self":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/238","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=238"}],"version-history":[{"count":0,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/238\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=238"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=238"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=238"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}