<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 9, 2014 at 6:12 PM, gettimothy <span dir="ltr">&lt;<a href="mailto:gettimothy@zoho.com" target="_blank">gettimothy@zoho.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> <br><u></u><div><div style="font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif">
<div>What is an &quot;exit trap&quot; ? Cleanup on fail?<br></div></div></div></blockquote><div><br></div><div>It can do, yes.  But what it does is cause the script to exit.  If you&#39;re looping over other scripts, as in</div>
<div><br></div><div>        #!/bin/bash</div><div>        for d in newspeak.cog.* newspeak.stack.* squeak.*; do<br></div><div>                if test -d &quot;$d&quot;; then</div><div>                        (cd $d;./makeallclean)</div>
<div>                else</div><div>                        echo no $d directory found</div><div>                fi</div><div>        done </div><div><br></div><div>and you hit control-C halfway through then the control-C will simply kill the inner script, and the outer script will continue runnign, invoking the next script in the list.  So one ends up hitting control-C in some demented fashion until every script has been killed.</div>
<div><br></div><div>Add an exit trap though:</div><div><br></div><div><div>        #!/bin/bash</div><div>        trap &#39;exit 2&#39; HUP INT PIPE TERM 0<br>        for d in newspeak.cog.* newspeak.stack.* squeak.*; do</div>
<div>                if test -d &quot;$d&quot;; then</div><div>                        (cd $d;./makeallclean)</div><div>                else</div><div>                        echo no $d directory found</div><div>                fi</div>
<div>        done </div><div><br></div></div><div>and the script will catch the ctrl-C and exit immediately.  And you can indeed add cleanup actions, e.g. from a script for diffing cr-line-ending files:</div><div><br></div>
<div><div>        Ftmp=/tmp/`basename &quot;$2&quot;`.$$</div><div>        trap &#39;rm -f &quot;$Ftmp&quot; 2&gt;/dev/null; exit 2&#39; HUP INT PIPE TERM 0</div><div>        if [ ! -f &quot;$2&quot; ]; then</div><div>            echo $0: $2: No such file.</div>
<div>            exit 1</div><div>        fi</div><div>        tr \\015 \\012 &lt;&quot;$2&quot; &gt;&quot;$Ftmp&quot;</div></div><div>        ...</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div style="font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif"><div></div><div><span style="font-size:10pt">That is the first time I have seen that term.</span><br></div></div></blockquote><div><br></div><div>
It might not be the right term, but hopefully you get what I mean :-)</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div><div style="font-size:10pt;font-family:Verdana,Arial,Helvetica,sans-serif"><div><span style="font-size:10pt">thx.</span><br></div><div><br></div><div>tty</div></div></div></blockquote></div><div><br></div>-- <br>best,<div>
Eliot</div>
</div></div>