<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 5, 2014 at 6:45 AM, Sean Dague <span dir="ltr"><<a href="mailto:sean@dague.net" target="_blank">sean@dague.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I got bit by another bug yesterday where there was a typo between<br>
variables in the source tree. So I started down the process of set -o<br>
nounset to see how bad it would be to prevent that in the future.<br></blockquote><div><br></div><div>[...] </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The trueorfalse issue can be fixed if we change the function to be:<br>
<br>
function trueorfalse {<br>
    local xtrace=$(set +o | grep xtrace)<br>
    set +o xtrace<br>
    local default=$1<br>
    local testval="${!2+x}"<br>
<br>
    [[ -z "$testval" ]] && { echo "$default"; return; }<br></blockquote><div><br></div><div>There should be an $xtrace in that return path</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
    [[ "0 no No NO false False FALSE" =~ "$testval" ]] && { echo<br>
"False"; return; }<br>
    [[ "1 yes Yes YES true True TRUE" =~ "$testval" ]] && { echo "True";<br>
return; }<br>
    echo "$default"<br>
    $xtrace<br>
}<br>
<br>
<br>
FOO=$(trueorfalse True FOO)<br>
<br>
... then works.<br></blockquote><div><br></div><div>I'm good with this.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
the -z and -n bits can be addressed with either FOO=${FOO:-} or an isset<br>
function that interpolates. FOO=${FOO:-} actually feels better to me<br>
because it's part of the spirit of things.<br></blockquote><div><br></div><div>I think I agree, but we have a lot og is_*() functions so that wouldn't be to far of a departure, I could be convinced either way I suppose.  This is going to be the hard part of the cleanup and ongoing enforcement.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So... the question is, is this worth it? It's going to have fall out in<br>
lesser used parts of the code where we don't catch things (like -o<br>
errexit did). However it should help flush out a class of bugs in the<br>
process.<br></blockquote><div><br></div><div>This is going to be a long process to do the change, I think we will need to bracket parts of the code as they get cleaned up to avoid regressions slipping in.</div></div><div><br></div><div>dt</div><div><br></div>-- <br><div class="gmail_signature"><br>Dean Troyer<br><a href="mailto:dtroyer@gmail.com">dtroyer@gmail.com</a><br></div>
</div></div>