<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-7625526986034013157.post2816649910785487170..comments</id><updated>2011-11-11T07:30:48.529-08:00</updated><category term='plugins rails'/><category term='essays'/><category term='ruby'/><category term='git-tmbundle'/><category term='vim'/><category term='textmate'/><category term='solutions'/><category term='javascript'/><category term='git'/><category term='nerd'/><title type='text'>Comments on Tim, the Enchanter: How to escape arguments in bash</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://tim.theenchanter.com/feeds/2816649910785487170/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default'/><link rel='alternate' type='text/html' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html'/><author><name>Tim Harper</name><uri>http://www.blogger.com/profile/03349408198556972919</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://4.bp.blogspot.com/_7HPuw-ljjoY/S7eBtBJOBlI/AAAAAAAAAhg/Oo_4-NSOb6k/S220/tim.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7625526986034013157.post-4751431215627296974</id><published>2011-11-11T00:55:20.427-08:00</published><updated>2011-11-11T00:55:20.427-08:00</updated><title type='text'>I was about to use your trick but some coworkers p...</title><content type='html'>I was about to use your trick but some coworkers pointed out that there&amp;#39;s a more elegant way to escape a string in bash, namely:&lt;br /&gt;&lt;br /&gt;function escape() {&lt;br /&gt;  return printf &amp;#39;%q&amp;#39; &amp;quot;$@&amp;quot;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;then you can just &lt;br /&gt;&lt;br /&gt;ssh user@host &amp;quot;$(escape $COMMAND $ARGS)&amp;quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/4751431215627296974'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/4751431215627296974'/><link rel='alternate' type='text/html' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html?showComment=1321001720427#c4751431215627296974' title=''/><author><name>Antonio Ramírez</name><uri>http://www.blogger.com/profile/14585354496095750534</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html' ref='tag:blogger.com,1999:blog-7625526986034013157.post-2816649910785487170' source='http://www.blogger.com/feeds/7625526986034013157/posts/default/2816649910785487170' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1687058474'/></entry><entry><id>tag:blogger.com,1999:blog-7625526986034013157.post-4100690576411860487</id><published>2009-11-13T00:06:28.130-08:00</published><updated>2009-11-13T00:06:28.130-08:00</updated><title type='text'>http://mywiki.wooledge.org/BashFAQ/096</title><content type='html'>http://mywiki.wooledge.org/BashFAQ/096</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/4100690576411860487'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/4100690576411860487'/><link rel='alternate' type='text/html' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html?showComment=1258099588130#c4100690576411860487' title=''/><author><name>pgas</name><uri>http://www.blogger.com/profile/08934589048740165236</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html' ref='tag:blogger.com,1999:blog-7625526986034013157.post-2816649910785487170' source='http://www.blogger.com/feeds/7625526986034013157/posts/default/2816649910785487170' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-1269293738'/></entry><entry><id>tag:blogger.com,1999:blog-7625526986034013157.post-6633373956736161164</id><published>2009-11-09T17:34:15.782-08:00</published><updated>2009-11-09T17:34:15.782-08:00</updated><title type='text'>Hello Tim,

be careful, your script works for 9 ar...</title><content type='html'>Hello Tim,&lt;br /&gt;&lt;br /&gt;be careful, your script works for 9 arguments at most.  To surpass this restriction, try this change:&lt;br /&gt;&lt;br /&gt;COMMAND=&amp;quot;$1&amp;quot;; shift; &lt;br /&gt;ARGS=&amp;quot;&amp;quot; &lt;br /&gt;for (( i = 1; i &amp;lt;= $# ; i++ )); do &lt;br /&gt;&lt;b&gt;eval ARG=\${$i}&lt;/b&gt; &lt;br /&gt;ARGS=&amp;quot;$ARGS $(echo -n &amp;quot;$ARG&amp;quot; | awk &amp;#39;BEGIN{RS=&amp;quot;&amp;quot;} {gsub(&amp;quot;[^\\\n]&amp;quot;, &amp;quot;\\\\&amp;amp;&amp;quot;);gsub(&amp;quot;\\\n&amp;quot;, &amp;quot;$&amp;#39;&amp;quot;&amp;#39;&amp;quot;&amp;#39;\\n&amp;#39;&amp;quot;&amp;#39;&amp;quot;&amp;#39;&amp;quot;);print}&amp;#39;)&amp;quot; &lt;br /&gt;done &lt;br /&gt;ssh user@host &amp;quot;$COMMAND&amp;quot; &amp;quot;$ARGS&amp;quot;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/6633373956736161164'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/6633373956736161164'/><link rel='alternate' type='text/html' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html?showComment=1257816855782#c6633373956736161164' title=''/><author><name>Luis-Miguel</name><uri>http://www.blogger.com/profile/07560981031362310880</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html' ref='tag:blogger.com,1999:blog-7625526986034013157.post-2816649910785487170' source='http://www.blogger.com/feeds/7625526986034013157/posts/default/2816649910785487170' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2124204889'/></entry><entry><id>tag:blogger.com,1999:blog-7625526986034013157.post-8815108528506075145</id><published>2009-10-27T01:04:51.055-07:00</published><updated>2009-10-27T01:04:51.055-07:00</updated><title type='text'>That&amp;#39;s weird, for me a simple \&amp;quot; seems to...</title><content type='html'>That&amp;#39;s weird, for me a simple \&amp;quot; seems to work:&lt;br /&gt;&lt;br /&gt;$ ssh me@server grep &amp;quot;1 2&amp;quot; somefile&lt;br /&gt;&lt;br /&gt;does the right thing.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/8815108528506075145'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/8815108528506075145'/><link rel='alternate' type='text/html' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html?showComment=1256630691055#c8815108528506075145' title=''/><author><name>Chris Stork</name><uri>http://www.blogger.com/profile/09610041247191384696</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html' ref='tag:blogger.com,1999:blog-7625526986034013157.post-2816649910785487170' source='http://www.blogger.com/feeds/7625526986034013157/posts/default/2816649910785487170' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-489042765'/></entry><entry><id>tag:blogger.com,1999:blog-7625526986034013157.post-601744467521722956</id><published>2009-03-09T08:53:00.000-07:00</published><updated>2009-03-09T08:53:00.000-07:00</updated><title type='text'>From Jeff Snyder (relayed via email because his co...</title><content type='html'>From Jeff Snyder (relayed via email because his company blocks blogger.com)&lt;BR/&gt;&lt;BR/&gt;Hi Tim,&lt;BR/&gt;&lt;BR/&gt;I found myself trying to pass arguments verbatim through ssh verbatim today and came across your blog :-) &lt;BR/&gt;I&amp;#39;d have left this as a comment, but my company web proxy blocks blogger.com, so email it is.&lt;BR/&gt;&lt;BR/&gt;Anyway.. I also was somewhat irritated that bash doesn&amp;#39;t provide a builtin for it, you really shouldn&amp;#39;t need to resort to awk magic to get something like this to work. But your solution was the best I found from a quick googling&lt;BR/&gt;&lt;BR/&gt;I tested a few things with it and thought it was bulletproof at first, but unfotunately it chokes on newlines and ssh ends up executing everything after a newline as a separate command on the remote host&lt;BR/&gt;&lt;BR/&gt;Here&amp;#39;s what I&amp;#39;ve ended up with:&lt;BR/&gt;&lt;BR/&gt;COMMAND=&amp;quot;$1&amp;quot;; shift; &lt;BR/&gt;ARGS=&amp;quot;&amp;quot; &lt;BR/&gt;for (( i = 1; i &amp;lt;= $# ; i++ )); do &lt;BR/&gt;    eval ARG=\$$i &lt;BR/&gt;    ARGS=&amp;quot;$ARGS $(echo -n &amp;quot;$ARG&amp;quot; | awk &amp;#39;BEGIN{RS=&amp;quot;&amp;quot;} {gsub(&amp;quot;[^\\\n]&amp;quot;, &amp;quot;\\\\&amp;amp;&amp;quot;);gsub(&amp;quot;\\\n&amp;quot;, &amp;quot;$&amp;#39;&amp;quot;&amp;#39;&amp;quot;&amp;#39;\\n&amp;#39;&amp;quot;&amp;#39;&amp;quot;&amp;#39;&amp;quot;);print}&amp;#39;)&amp;quot; &lt;BR/&gt;done &lt;BR/&gt;ssh user@host &amp;quot;$COMMAND&amp;quot; &amp;quot;$ARGS&amp;quot;&lt;BR/&gt;&lt;BR/&gt;.. not very pretty.&lt;BR/&gt;&lt;BR/&gt;Have you found anything better since you blogged about it?</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/601744467521722956'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7625526986034013157/2816649910785487170/comments/default/601744467521722956'/><link rel='alternate' type='text/html' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html?showComment=1236613980000#c601744467521722956' title=''/><author><name>Tim Harper</name><uri>http://www.blogger.com/profile/03349408198556972919</uri><email>noreply@blogger.com</email><gd:image xmlns:gd='http://schemas.google.com/g/2005' rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://2.bp.blogspot.com/_7HPuw-ljjoY/SVsGwfOz6bI/AAAAAAAAAcE/xohK24cotq8/S220/DSC04586.JPG'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tim.theenchanter.com/2009/02/how-to-escape-arguments-in-bash.html' ref='tag:blogger.com,1999:blog-7625526986034013157.post-2816649910785487170' source='http://www.blogger.com/feeds/7625526986034013157/posts/default/2816649910785487170' type='text/html'/><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='blogger.itemClass' value='pid-2142473342'/></entry></feed>
