{"id":20,"date":"2010-08-21T18:41:13","date_gmt":"2010-08-21T23:41:13","guid":{"rendered":"http:\/\/soljerome.com\/blog\/?p=20"},"modified":"2010-08-27T04:39:20","modified_gmt":"2010-08-27T09:39:20","slug":"bash-plus-read","status":"publish","type":"post","link":"https:\/\/www.soljerome.com\/blog\/2010\/08\/21\/bash-plus-read\/","title":{"rendered":"bash and POSIX read"},"content":{"rendered":"<p>At work the other day, I found myself needing to install a bunch of gems with differing versions. I had a file created that looked something like this which had all the gems (along with specific versions) that were requested to be installed:<\/p>\n<pre>foo --version 1\r\nbar --version 2\r\nfoobar --version 3<\/pre>\n<p>So, I tried running a bash for loop over the items to get them installed. However, I soon found that this wasn&#8217;t going to work:<\/p>\n<pre>$ for gem in `cat gems`; do echo $gem; done\r\nfoo\r\n--version\r\n1\r\nbar\r\n--version\r\n2\r\nfoobar\r\n--version\r\n3<\/pre>\n<p>Bash was using any <a href=\"http:\/\/www.faqs.org\/docs\/abs\/HTML\/variables2.html#IFSH\" target=\"_blank\">whitespace<\/a> separator as indication of a new item in the loop. After searching around for a bit, I found that you can use the POSIX read utility to make this work as expected.<\/p>\n<pre>$ cat gems | while read line; do echo $line; done\r\nfoo --version 1\r\nbar --version 2\r\nfoobar --version 3<\/pre>\n<p>Exactly what I needed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>At work the other day, I found myself needing to install a bunch of gems with differing versions. I had a file created that looked something like this which had all the gems (along with specific versions) that were requested to be installed: foo &#8211;version 1 bar &#8211;version 2 foobar &#8211;version 3 So, I tried <a href='https:\/\/www.soljerome.com\/blog\/2010\/08\/21\/bash-plus-read\/' class='excerpt-more'>[&#8230;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts\/20"}],"collection":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/comments?post=20"}],"version-history":[{"count":8,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions"}],"predecessor-version":[{"id":49,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/posts\/20\/revisions\/49"}],"wp:attachment":[{"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/media?parent=20"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/categories?post=20"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.soljerome.com\/blog\/wp-json\/wp\/v2\/tags?post=20"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}