<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Aug 12, 2015 at 10:46 AM, Christopher Larson <span dir="ltr">&lt;<a href="mailto:clarson@kergoth.com" target="_blank">clarson@kergoth.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><div class="gmail_quote">On Wed, Aug 12, 2015 at 9:56 AM, Khem Raj <span dir="ltr">&lt;<a href="mailto:raj.khem@gmail.com" target="_blank">raj.khem@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Wed, Aug 12, 2015 at 2:49 AM,  &lt;<a href="mailto:Mikko.Rapeli@bmw.de" target="_blank">Mikko.Rapeli@bmw.de</a>&gt; wrote:<br>
&gt; This reminded me of the problems I&#39;ve seen with various oe-core shell scripts:<br>
&gt; they are missing systematic error handling.<br>
&gt;<br>
&gt; IMO using bash and &#39;set -euxo pipefail&#39; are a good approach to catch errors<br>
&gt; early in shell scripts. Manually checking for $? is error prone and things<br>
&gt; like pipes can hide them. Using undefined variables is another thing<br>
&gt; which should fail early before things go horribly wrong. And in build automation<br>
&gt; I&#39;d rather see output of -x since things can fail in mysterious ways.<br>
&gt; And then there&#39;s quoting....<br>
&gt;<br>
&gt; One useful guide is to use shellcheck as static analysis tool for shell scripts.<br>
&gt;<br>
&gt; I guess internally <span><span class="il">bitbake</span></span> uses at least set -e.<br>
&gt;<br>
&gt; Comments?<br>
<br>
</span>all these are good suggestions, I would recommend to open bugs for all<br>
of these some of them might need<br>
to cite the scripts which need fixing.</blockquote></div><br></span>Agreed, it&#39;s important to check the behavior of shell scripts is kosher and standards-compliant. shellcheck is extremely useful, I recommend it as well, but combined with the vim syntastic plugin, so every time you save the file all the errors and warnings are identified :) Makes it harder to ignore or forget about.</blockquote></div><br>That reminds me, there&#39;s a shell portability issue / standards-complaince issue that&#39;s not identified by shellcheck. Typically, to negate a  bracket expression in a regular expression, one uses ^, e.g. [^a-z] is everything that isn&#39;t in the range a to z, but that&#39;s not the case in shell, e.g. at a prompt or in a ${foo#&lt;pattern&gt;}:</div><div class="gmail_extra"><br></div><div class="gmail_extra">    &quot;[...]a bracket expression as in XBD <i>RE Bracket
Expression</i> , except that the &lt;exclamation-mark&gt; character ( <tt>&#39;!&#39;</tt> ) shall replace the &lt;circumflex&gt;
character ( <tt>&#39;^&#39;</tt> ) in its role in a non-matching list in the regular expression notation&quot;</div><div class="gmail_extra"><br></div><div class="gmail_extra">So in shell, you&#39;d want [!a-z] rather than [^a-z]. Nearly all shells handle both, but the behavior of the latter is actually unspecified according to the standard:</div><div class="gmail_extra"><br></div><div class="gmail_extra">    &quot;A bracket expression starting with an unquoted &lt;circumflex&gt; character produces unspecified results.&quot;</div><div class="gmail_extra"><br></div><div class="gmail_extra">I recently got bitten by this with one of my shell scripts on a system running dash.<br>-- <br><div class="gmail_signature">Christopher Larson<br>clarson at kergoth dot com<br>Founder - BitBake, OpenEmbedded, OpenZaurus<br>Maintainer - Tslib<br>Senior Software Engineer, Mentor Graphics</div>
</div></div>