{"id":690,"date":"2012-06-01T20:01:19","date_gmt":"2012-06-01T18:01:19","guid":{"rendered":"http:\/\/www.small-apps.com\/?p=690"},"modified":"2018-09-25T03:01:33","modified_gmt":"2018-09-25T01:01:33","slug":"spot-the-error-can-you-quote-correctly","status":"publish","type":"post","link":"https:\/\/www.small-apps.com\/de\/2012\/06\/spot-the-error-can-you-quote-correctly\/","title":{"rendered":"Spot the error: Can you quote correctly?"},"content":{"rendered":"<p>In an attempt to make my many programming experiments last and live longer than my hard disk might live, I wanted to create a remote copy of my git repositories.<\/p>\n<p>So I programmed the following line<\/p>\n<p><code>for i in *;\u00a0do if test -d $i\/.git; then (git clone --bare $i \/Volumes\/Backup\/Git\/$i.git); fi; done<\/code><\/p>\n<p>Of course I had a problem, that I had not expected. Can you spot it? It is not, that \u00a0I used parenthesis, where they are not needed. I kept them, because I first wanted to program (cd $i; &#8230;). But this would have been &#8222;wrong&#8220; too. So what is it? Of course, it is using $i without quotes!<\/p>\n<p>&#8222;Back in the good old days&#8220; nobody liked spaces in files or directories. It made all programming and typing a pain. So back then, the above line was not only common, but more or less seen as &#8222;correct&#8220;. But nowadays even my Xcode projects sometimes have blanks in their filenames. So the correct version is this one:<\/p>\n<p><code>for i in *; do if test -d \"$i\"\/.git; then (git clone --bare \"$i\" \/Volumes\/Backup\/Git\/\"$i\".git); fi; done<\/code><\/p>\n<p>Why is it &#8222;$i&#8220; instead of &#8218;$i&#8216;, `$i`\u00a0or \u00b4$i\u00b4?\u00a0I assume, you know that &#8222;$i&#8220; is quoting including substitution\/evaluation of the variable i, &#8218;$i&#8216; is quoting the variable without substituting it and that `$i` will substitute $i with the shell-execution result of $i&#8217;s content after evaluation. And \u00b4$i\u00b4? \u00a0That&#8217;s no quote at all, just two special characters.<\/p>\n<p>Small programs (and program errors) like this made programmers like me superstitious: Never use blanks in filenames. I still try to avoid them, but the &#8222;forces of the evil blank&#8220; are so nice, sweet and appealing&#8230;<\/p>","protected":false},"excerpt":{"rendered":"<p>In an attempt to make my many programming experiments last and live longer than my hard disk might live, I wanted to create a remote copy of my git repositories. So I programmed the following line for i in *;\u00a0do if test -d $i\/.git; then (git clone &#8211;bare $i \/Volumes\/Backup\/Git\/$i.git); fi; done Of course I &hellip; <a href=\"https:\/\/www.small-apps.com\/de\/2012\/06\/spot-the-error-can-you-quote-correctly\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eSpot the error: Can you quote correctly?\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-690","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/posts\/690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/comments?post=690"}],"version-history":[{"count":4,"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/posts\/690\/revisions"}],"predecessor-version":[{"id":1034,"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/posts\/690\/revisions\/1034"}],"wp:attachment":[{"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/media?parent=690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/categories?post=690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.small-apps.com\/de\/wp-json\/wp\/v2\/tags?post=690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}