<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"><<a href="mailto:gettimothy@zoho.com" target="_blank">gettimothy@zoho.com</a>></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 "exit trap" ? 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'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 "$d"; 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 'exit 2' HUP INT PIPE TERM 0<br> for d in newspeak.cog.* newspeak.stack.* squeak.*; do</div>
<div> if test -d "$d"; 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 "$2"`.$$</div><div> trap 'rm -f "$Ftmp" 2>/dev/null; exit 2' HUP INT PIPE TERM 0</div><div> if [ ! -f "$2" ]; then</div><div> echo $0: $2: No such file.</div>
<div> exit 1</div><div> fi</div><div> tr \\015 \\012 <"$2" >"$Ftmp"</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>