<div dir="ltr">On Wed, Jun 11, 2014 at 5:08 AM, Elias Persson <span dir="ltr">&lt;<a href="mailto:delreich@takeit.se" target="_blank">delreich@takeit.se</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Maybe I&#39;m too sleep deprived to make sense of what I&#39;m reading,<br>
but...<br>
<div class=""><br>
On 2014-06-10 16:12, Karanbir Singh wrote:<br>
&gt; On 06/10/2014 03:08 PM, Pat Riehecky wrote:<br>
&gt;&gt; From: Pat Riehecky &lt;<a href="mailto:riehecky@fnal.gov">riehecky@fnal.gov</a>&gt;<br>
</div>&lt;snip&gt;<br>
<div class="">&gt;&gt; +#####################################################################<br>
&gt;&gt; +# setup args in the right order for making getopt evaluation<br>
&gt;&gt; +# nice and easy.  You&#39;ll need to read the manpages for more info<br>
&gt;&gt; +args=$(getopt -o hr -- &quot;$@&quot;)<br>
&gt;&gt; +if [[ $? -ne 0 ]]; then<br>
&gt;&gt; +    usage<br>
&gt;&gt; +fi<br>
&gt;&gt; +eval set -- &quot;$args&quot;<br>
&gt;&gt; +<br>
&gt;&gt; +RHELTAG=0<br>
&gt;&gt; +for arg in $@; do<br>
<br>
</div>Shouldn&#39;t this be quoted (or just `for arg;`)?<br>
Otherwise, why not just use `$args` and skip the `eval set ...`?<br></blockquote><div><br></div><div>Agreed. &quot;$@&quot; to preserve the argv array. Granted, I don&#39;t think the script is likely to run into any such cases, but still good practice. An unquoted $@ is a little silly anyway -- that&#39;s what $* is for.<br>

</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="">
&gt;&gt; +    case $1 in<br>
&gt;&gt; +        -- )<br>
&gt;&gt; +            # end of getopt args, shift off the -- and get out of the loop<br>
</div>&lt;snip&gt;<br>
<div class="">&gt;&gt; +    exit 1<br>
&gt;&gt; +fi<br>
&gt;&gt; +<br>
&gt;&gt; +msg=$(git log --pretty=format:&quot;%s&quot;)<br>
&gt;&gt; +pkg=$(echo ${msg} | cut -d&#39; &#39; -f2)<br>
<br>
</div>More missing quoting?<br>
<div class=""><br>
<br></div></blockquote><div><br></div><div>Well here it&#39;s actually arguable. You don&#39;t need quotes around a single command substitution in an assignment. Not that they&#39;d hurt anything<br><br></div><div>As for ${msg} vs &quot;${msg}&quot;, it&#39;s just a matter of collapsing whitespace.  In fact, unquoted is beneficial if there happens to be a stray space in the commit message.<br>

# msg=&quot;import  foo-1-1&quot;<br># pkg=$(echo ${msg} | cut -d&#39; &#39; -f2)<br># printf &quot;%q\n&quot; &quot;$pkg&quot;<br>foo-1-1<br># pkg=$(echo &quot;${msg}&quot; | cut -d&#39; &#39; -f2)<br># printf &quot;%q\n&quot; &quot;$pkg&quot;<br>

&#39;&#39;<br><br></div><div>Personally, I&#39;d probably just let bash do the splitting. E.g.<br># set -- $msg<br># pkg=&quot;$2&quot;<br># printf &quot;%q\n&quot; &quot;$pkg&quot;<br>foo-1-1<br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

<div class="">
&gt;&gt; +<br>
&gt;&gt; +if [[ ${RHELTAG} -eq 0 ]]; then<br>
&gt;&gt; +    thispkg=(echo ${pkg} | head -1)<br>
&gt;&gt; +elif [[ ${RHELTAG} -eq 1 ]]; then<br>
&gt;&gt; +    thispkg=(echo ${pkg} grep -v centos | head -1)<br>
<br>
</div>In addition to the already mentioned missing $:s, there should<br>
presumably be a pipe before that `grep`, and unless that `head`<br>
is redundant, `${pkg}` should be quoted.<br>
(Unless there&#39;s some portability issue I&#39;m missing, isn&#39;t<br>
`grep -v -m 1 -e centos` equivalent?)<br>
<div class="im"><br></div></blockquote><div><br></div><div>Yes, the pipe is missing and ${pkg} should be quoted. The head was not originally redundant, but one of my patches made it so (and inadvertently broke the script&#39;s -r option).<br>

</div><div> <br></div><div>Actually, about to post a new patch which will address the quoting and also allow the script to work even if the repo is cloned to a differently named directory.<br></div></div></div></div>