Debian Codegraph @

HTML/debugging.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <HTML
3 ><HEAD
4 ><TITLE
5 >Debugging</TITLE
6 ><META
7 NAME="GENERATOR"
8 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
9 "><LINK
10 REL="HOME"
11 TITLE="Advanced Bash-Scripting Guide"
12 HREF="index.html"><LINK
13 REL="UP"
14 TITLE="Advanced Topics"
15 HREF="part5.html"><LINK
16 REL="PREVIOUS"
17 TITLE="Of Zeros and Nulls"
18 HREF="zeros.html"><LINK
19 REL="NEXT"
20 TITLE="Options"
21 HREF="options.html"><META
22 HTTP-EQUIV="Content-Style-Type"
23 CONTENT="text/css"><LINK
24 REL="stylesheet"
25 HREF="common/kde-common.css"
26 TYPE="text/css"><META
27 HTTP-EQUIV="Content-Type"
28 CONTENT="text/html; charset=iso-8859-1"><META
29 HTTP-EQUIV="Content-Language"
30 CONTENT="en"><LINK
31 REL="stylesheet"
32 HREF="common/kde-localised.css"
33 TYPE="text/css"
34 TITLE="KDE-English"><LINK
35 REL="stylesheet"
36 HREF="common/kde-default.css"
37 TYPE="text/css"
38 TITLE="KDE-Default"></HEAD
39 ><BODY
40 CLASS="CHAPTER"
41 BGCOLOR="#FFFFFF"
42 TEXT="#000000"
43 LINK="#AA0000"
44 VLINK="#AA0055"
45 ALINK="#AA0000"
46 STYLE="font-family: sans-serif;"
47 ><DIV
48 CLASS="NAVHEADER"
49 ><TABLE
50 SUMMARY="Header navigation table"
51 WIDTH="100%"
52 BORDER="0"
53 CELLPADDING="0"
54 CELLSPACING="0"
55 ><TR
56 ><TH
57 COLSPAN="3"
58 ALIGN="center"
59 >Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH
60 ></TR
61 ><TR
62 ><TD
63 WIDTH="10%"
64 ALIGN="left"
65 VALIGN="bottom"
66 ><A
67 HREF="zeros.html"
68 ACCESSKEY="P"
69 >Prev</A
70 ></TD
71 ><TD
72 WIDTH="80%"
73 ALIGN="center"
74 VALIGN="bottom"
75 ></TD
76 ><TD
77 WIDTH="10%"
78 ALIGN="right"
79 VALIGN="bottom"
80 ><A
81 HREF="options.html"
82 ACCESSKEY="N"
83 >Next</A
84 ></TD
85 ></TR
86 ></TABLE
87 ><HR
88 ALIGN="LEFT"
89 WIDTH="100%"></DIV
90 ><DIV
91 CLASS="CHAPTER"
92 ><H1
93 ><A
94 NAME="DEBUGGING"
95 ></A
96 >Chapter 32. Debugging</H1
97 ><TABLE
98 BORDER="0"
99 WIDTH="100%"
100 CELLSPACING="0"
101 CELLPADDING="0"
102 CLASS="EPIGRAPH"
103 ><TR
104 ><TD
105 WIDTH="45%"
106 >&nbsp;</TD
107 ><TD
108 WIDTH="45%"
109 ALIGN="LEFT"
110 VALIGN="TOP"
111 ><I
112 ><P
113 ><I
114 >Debugging is twice as hard as writing the code in the first
115 place. Therefore, if you write the code as cleverly as possible,
116 you are, by definition, not smart enough to debug it.</I
117 ></P
118 ><P
119 ><I
120 >--Brian Kernighan</I
121 ></P
122 ></I
123 ></TD
124 ></TR
125 ></TABLE
126 ><P
127 >The Bash shell contains no built-in debugger, and only bare-bones
128 debugging-specific commands and constructs. Syntax errors or
129 outright typos in the script generate cryptic error messages that
130 are often of no help in debugging a non-functional script.</P
131 ><DIV
132 CLASS="EXAMPLE"
133 ><HR><A
134 NAME="EX74"
135 ></A
136 ><P
137 ><B
138 >Example 32-1. A buggy script</B
139 ></P
140 ><TABLE
141 BORDER="0"
142 BGCOLOR="#E0E0E0"
143 WIDTH="100%"
144 ><TR
145 ><TD
146 ><PRE
147 CLASS="PROGRAMLISTING"
148 > 1&nbsp;#!/bin/bash
149 2&nbsp;# ex74.sh
150 3&nbsp;
151 4&nbsp;# This is a buggy script.
152 5&nbsp;# Where, oh where is the error?
153 6&nbsp;
154 7&nbsp;a=37
155 8&nbsp;
156 9&nbsp;if [$a -gt 27 ]
157 10&nbsp;then
158 11&nbsp; echo $a
159 12&nbsp;fi
160 13&nbsp;
161 14&nbsp;exit $? # 0! Why?</PRE
162 ></TD
163 ></TR
164 ></TABLE
165 ><HR></DIV
166 ><P
167 >Output from script:
168 <TABLE
169 BORDER="0"
170 BGCOLOR="#E0E0E0"
171 WIDTH="100%"
172 ><TR
173 ><TD
174 ><PRE
175 CLASS="SCREEN"
176 > <TT
177 CLASS="COMPUTEROUTPUT"
178 >./ex74.sh: [37: command not found</TT
179 ></PRE
180 ></TD
181 ></TR
182 ></TABLE
183 >
184 What's wrong with the above script? Hint: after the
185 <I
186 CLASS="FIRSTTERM"
187 >if</I
188 >.</P
189 ><DIV
190 CLASS="EXAMPLE"
191 ><HR><A
192 NAME="MISSINGKEYWORD"
193 ></A
194 ><P
195 ><B
196 >Example 32-2. Missing <A
197 HREF="internal.html#KEYWORDREF"
198 >keyword</A
199 ></B
200 ></P
201 ><TABLE
202 BORDER="0"
203 BGCOLOR="#E0E0E0"
204 WIDTH="100%"
205 ><TR
206 ><TD
207 ><PRE
208 CLASS="PROGRAMLISTING"
209 > 1&nbsp;#!/bin/bash
210 2&nbsp;# missing-keyword.sh
211 3&nbsp;# What error message will this script generate? And why?
212 4&nbsp;
213 5&nbsp;for a in 1 2 3
214 6&nbsp;do
215 7&nbsp; echo "$a"
216 8&nbsp;# done # Required keyword 'done' commented out in line 8.
217 9&nbsp;
218 10&nbsp;exit 0 # Will not exit here!
219 11&nbsp;
220 12&nbsp;# === #
221 13&nbsp;
222 14&nbsp;# From command line, after script terminates:
223 15&nbsp; echo $? # 2</PRE
224 ></TD
225 ></TR
226 ></TABLE
227 ><HR></DIV
228 ><P
229 >Output from script:
230 <TABLE
231 BORDER="0"
232 BGCOLOR="#E0E0E0"
233 WIDTH="100%"
234 ><TR
235 ><TD
236 ><PRE
237 CLASS="SCREEN"
238 > <TT
239 CLASS="COMPUTEROUTPUT"
240 >missing-keyword.sh: line 10: syntax error: unexpected end of file</TT
241 >
242 </PRE
243 ></TD
244 ></TR
245 ></TABLE
246 >
247 Note that the error message does <SPAN
248 CLASS="emphasis"
249 ><I
250 CLASS="EMPHASIS"
251 >not</I
252 ></SPAN
253 > necessarily
254 reference the line in which the error occurs, but the line where the
255 Bash interpreter finally becomes aware of the error.
256 </P
257 ><P
258 >Error messages may disregard comment lines in a script when
259 reporting the line number of a syntax error.</P
260 ><P
261 >What if the script executes, but does not work as expected? This is the
262 all too familiar logic error.</P
263 ><DIV
264 CLASS="EXAMPLE"
265 ><HR><A
266 NAME="EX75"
267 ></A
268 ><P
269 ><B
270 >Example 32-3. <I
271 CLASS="FIRSTTERM"
272 >test24</I
273 >: another buggy script</B
274 ></P
275 ><TABLE
276 BORDER="0"
277 BGCOLOR="#E0E0E0"
278 WIDTH="100%"
279 ><TR
280 ><TD
281 ><PRE
282 CLASS="PROGRAMLISTING"
283 > 1&nbsp;#!/bin/bash
284 2&nbsp;
285 3&nbsp;# This script is supposed to delete all filenames in current directory
286 4&nbsp;#+ containing embedded spaces.
287 5&nbsp;# It doesn't work.
288 6&nbsp;# Why not?
289 7&nbsp;
290 8&nbsp;
291 9&nbsp;badname=`ls | grep ' '`
292 10&nbsp;
293 11&nbsp;# Try this:
294 12&nbsp;# echo "$badname"
295 13&nbsp;
296 14&nbsp;rm "$badname"
297 15&nbsp;
298 16&nbsp;exit 0</PRE
299 ></TD
300 ></TR
301 ></TABLE
302 ><HR></DIV
303 ><P
304 >Try to find out what's wrong with <A
305 HREF="debugging.html#EX75"
306 >Example 32-3</A
307 >
308 by uncommenting the <TT
309 CLASS="USERINPUT"
310 ><B
311 >echo "$badname"</B
312 ></TT
313 > line. Echo
314 statements are useful for seeing whether what you expect is
315 actually what you get.</P
316 ><P
317 >In this particular case, <TT
318 CLASS="USERINPUT"
319 ><B
320 >rm "$badname"</B
321 ></TT
322 >
323 will not give the desired results because
324 <TT
325 CLASS="VARNAME"
326 >$badname</TT
327 > should not be quoted. Placing it
328 in quotes ensures that <B
329 CLASS="COMMAND"
330 >rm</B
331 > has only one
332 argument (it will match only one filename). A partial fix
333 is to remove to quotes from <TT
334 CLASS="VARNAME"
335 >$badname</TT
336 > and
337 to reset <TT
338 CLASS="VARNAME"
339 >$IFS</TT
340 > to contain only a newline,
341 <TT
342 CLASS="USERINPUT"
343 ><B
344 >IFS=$'\n'</B
345 ></TT
346 >. However, there are simpler
347 ways of going about it.
348 <TABLE
349 BORDER="0"
350 BGCOLOR="#E0E0E0"
351 WIDTH="100%"
352 ><TR
353 ><TD
354 ><PRE
355 CLASS="PROGRAMLISTING"
356 > 1&nbsp;# Correct methods of deleting filenames containing spaces.
357 2&nbsp;rm *\ *
358 3&nbsp;rm *" "*
359 4&nbsp;rm *' '*
360 5&nbsp;# Thank you. S.C.</PRE
361 ></TD
362 ></TR
363 ></TABLE
364 >
365
366 </P
367 ><P
368 >Summarizing the symptoms of a buggy script,
369 <OL
370 TYPE="1"
371 ><LI
372 ><P
373 >It bombs with a <SPAN
374 CLASS="QUOTE"
375 >"<SPAN
376 CLASS="ERRORNAME"
377 >syntax error</SPAN
378 >"</SPAN
379 > message, or</P
380 ></LI
381 ><LI
382 ><P
383 >It runs, but does not work as expected
384 (<SPAN
385 CLASS="ERRORNAME"
386 >logic error</SPAN
387 >).</P
388 ></LI
389 ><LI
390 ><P
391 >It runs, works as expected, but has nasty side effects
392 (<SPAN
393 CLASS="ERRORNAME"
394 >logic bomb</SPAN
395 >).</P
396 ></LI
397 ></OL
398 >
399 </P
400 ><P
401 ><A
402 NAME="DEBUGTOOLS"
403 ></A
404 ></P
405 ><P
406 >Tools for debugging non-working scripts include
407 <OL
408 TYPE="1"
409 ><LI
410 ><P
411 >Inserting <A
412 HREF="internal.html#ECHOREF"
413 >echo</A
414 >
415 statements at critical points in the script to trace the
416 variables, and otherwise give a snapshot of what is going
417 on.</P
418 ><DIV
419 CLASS="TIP"
420 ><TABLE
421 CLASS="TIP"
422 WIDTH="90%"
423 BORDER="0"
424 ><TR
425 ><TD
426 WIDTH="25"
427 ALIGN="CENTER"
428 VALIGN="TOP"
429 ><IMG
430 SRC="common/tip.png"
431 HSPACE="5"
432 ALT="Tip"></TD
433 ><TD
434 ALIGN="LEFT"
435 VALIGN="TOP"
436 ><P
437 >Even better is an <B
438 CLASS="COMMAND"
439 >echo</B
440 > that echoes
441 only when <I
442 CLASS="FIRSTTERM"
443 >debug</I
444 > is on.</P
445 ><P
446 ><TABLE
447 BORDER="0"
448 BGCOLOR="#E0E0E0"
449 WIDTH="90%"
450 ><TR
451 ><TD
452 ><PRE
453 CLASS="PROGRAMLISTING"
454 > 1&nbsp;### debecho (debug-echo), by Stefano Falsetto ###
455 2&nbsp;### Will echo passed parameters only if DEBUG is set to a value. ###
456 3&nbsp;debecho () {
457 4&nbsp; if [ ! -z "$DEBUG" ]; then
458 5&nbsp; echo "$1" &#62;&#38;2
459 6&nbsp; # ^^^ to stderr
460 7&nbsp; fi
461 8&nbsp;}
462 9&nbsp;
463 10&nbsp;DEBUG=on
464 11&nbsp;Whatever=whatnot
465 12&nbsp;debecho $Whatever # whatnot
466 13&nbsp;
467 14&nbsp;DEBUG=
468 15&nbsp;Whatever=notwhat
469 16&nbsp;debecho $Whatever # (Will not echo.)</PRE
470 ></TD
471 ></TR
472 ></TABLE
473 ></P
474 ></TD
475 ></TR
476 ></TABLE
477 ></DIV
478 ></LI
479 ><LI
480 ><P
481 >Using the <A
482 HREF="extmisc.html#TEEREF"
483 >tee</A
484 > filter
485 to check processes or data flows at critical points.</P
486 ></LI
487 ><LI
488 ><P
489 >Setting option flags <TT
490 CLASS="OPTION"
491 >-n -v -x</TT
492 ></P
493 ><P
494 ><TT
495 CLASS="USERINPUT"
496 ><B
497 >sh -n scriptname</B
498 ></TT
499 > checks for
500 syntax errors without actually running the script. This is
501 the equivalent of inserting <TT
502 CLASS="USERINPUT"
503 ><B
504 >set -n</B
505 ></TT
506 > or
507 <TT
508 CLASS="USERINPUT"
509 ><B
510 >set -o noexec</B
511 ></TT
512 > into the script. Note
513 that certain types of syntax errors can slip past this
514 check.</P
515 ><P
516 ><TT
517 CLASS="USERINPUT"
518 ><B
519 >sh -v scriptname</B
520 ></TT
521 > echoes each
522 command before executing it. This is the equivalent of
523 inserting <TT
524 CLASS="USERINPUT"
525 ><B
526 >set -v</B
527 ></TT
528 > or <TT
529 CLASS="USERINPUT"
530 ><B
531 >set
532 -o verbose</B
533 ></TT
534 > in the script.</P
535 ><P
536 >The <TT
537 CLASS="OPTION"
538 >-n</TT
539 > and <TT
540 CLASS="OPTION"
541 >-v</TT
542 >
543 flags work well together. <TT
544 CLASS="USERINPUT"
545 ><B
546 >sh -nv
547 scriptname</B
548 ></TT
549 > gives a verbose syntax check.</P
550 ><P
551 ><TT
552 CLASS="USERINPUT"
553 ><B
554 >sh -x scriptname</B
555 ></TT
556 > echoes the result each
557 command, but in an abbreviated manner. This is the equivalent of
558 inserting <TT
559 CLASS="USERINPUT"
560 ><B
561 >set -x</B
562 ></TT
563 > or
564 <TT
565 CLASS="USERINPUT"
566 ><B
567 >set -o xtrace</B
568 ></TT
569 > in the script.</P
570 ><P
571 ><A
572 NAME="UNDVARERR"
573 ></A
574 ></P
575 ><P
576 >Inserting <TT
577 CLASS="USERINPUT"
578 ><B
579 >set -u</B
580 ></TT
581 > or
582 <TT
583 CLASS="USERINPUT"
584 ><B
585 >set -o nounset</B
586 ></TT
587 > in the script runs it, but
588 gives an <SPAN
589 CLASS="ERRORNAME"
590 >unbound variable</SPAN
591 > error message
592 and aborts the script.
593 <TABLE
594 BORDER="0"
595 BGCOLOR="#E0E0E0"
596 WIDTH="90%"
597 ><TR
598 ><TD
599 ><PRE
600 CLASS="PROGRAMLISTING"
601 > 1&nbsp;set -u # Or set -o nounset
602 2&nbsp;
603 3&nbsp;# Setting a variable to null will not trigger the error/abort.
604 4&nbsp;# unset_var=
605 5&nbsp;
606 6&nbsp;echo $unset_var # Unset (and undeclared) variable.
607 7&nbsp;
608 8&nbsp;echo "Should not echo!"
609 9&nbsp;
610 10&nbsp;# sh t2.sh
611 11&nbsp;# t2.sh: line 6: unset_var: unbound variable</PRE
612 ></TD
613 ></TR
614 ></TABLE
615 ></P
616 ></LI
617 ><LI
618 ><P
619 >Using an <SPAN
620 CLASS="QUOTE"
621 >"assert"</SPAN
622 > function to test a
623 variable or condition at critical points in a script. (This is
624 an idea borrowed from C.)</P
625 ><DIV
626 CLASS="EXAMPLE"
627 ><HR><A
628 NAME="ASSERT"
629 ></A
630 ><P
631 ><B
632 >Example 32-4. Testing a condition with an
633 <I
634 CLASS="FIRSTTERM"
635 >assert</I
636 ></B
637 ></P
638 ><TABLE
639 BORDER="0"
640 BGCOLOR="#E0E0E0"
641 WIDTH="90%"
642 ><TR
643 ><TD
644 ><PRE
645 CLASS="PROGRAMLISTING"
646 > 1&nbsp;#!/bin/bash
647 2&nbsp;# assert.sh
648 3&nbsp;
649 4&nbsp;#######################################################################
650 5&nbsp;assert () # If condition false,
651 6&nbsp;{ #+ exit from script
652 7&nbsp; #+ with appropriate error message.
653 8&nbsp; E_PARAM_ERR=98
654 9&nbsp; E_ASSERT_FAILED=99
655 10&nbsp;
656 11&nbsp;
657 12&nbsp; if [ -z "$2" ] # Not enough parameters passed
658 13&nbsp; then #+ to assert() function.
659 14&nbsp; return $E_PARAM_ERR # No damage done.
660 15&nbsp; fi
661 16&nbsp;
662 17&nbsp; lineno=$2
663 18&nbsp;
664 19&nbsp; if [ ! $1 ]
665 20&nbsp; then
666 21&nbsp; echo "Assertion failed: \"$1\""
667 22&nbsp; echo "File \"$0\", line $lineno" # Give name of file and line number.
668 23&nbsp; exit $E_ASSERT_FAILED
669 24&nbsp; # else
670 25&nbsp; # return
671 26&nbsp; # and continue executing the script.
672 27&nbsp; fi
673 28&nbsp;} # Insert a similar assert() function into a script you need to debug.
674 29&nbsp;#######################################################################
675 30&nbsp;
676 31&nbsp;
677 32&nbsp;a=5
678 33&nbsp;b=4
679 34&nbsp;condition="$a -lt $b" # Error message and exit from script.
680 35&nbsp; # Try setting "condition" to something else
681 36&nbsp; #+ and see what happens.
682 37&nbsp;
683 38&nbsp;assert "$condition" $LINENO
684 39&nbsp;# The remainder of the script executes only if the "assert" does not fail.
685 40&nbsp;
686 41&nbsp;
687 42&nbsp;# Some commands.
688 43&nbsp;# Some more commands . . .
689 44&nbsp;echo "This statement echoes only if the \"assert\" does not fail."
690 45&nbsp;# . . .
691 46&nbsp;# More commands . . .
692 47&nbsp;
693 48&nbsp;exit $?</PRE
694 ></TD
695 ></TR
696 ></TABLE
697 ><HR></DIV
698 ></LI
699 ><LI
700 ><P
701 >Using the <A
702 HREF="variables2.html#LINENOREF"
703 >$LINENO</A
704 >
705 variable and the <A
706 HREF="internal.html#CALLERREF"
707 >caller</A
708 >
709 builtin.</P
710 ></LI
711 ><LI
712 ><P
713 ><A
714 NAME="DEBUGTRAP"
715 ></A
716 >Trapping at exit.</P
717 ><P
718 >The <A
719 HREF="internal.html#EXITREF"
720 >exit</A
721 > command in a script
722 triggers a signal <SPAN
723 CLASS="RETURNVALUE"
724 >0</SPAN
725 >, terminating
726 the process, that is, the script itself.
727
728 <A
729 NAME="AEN19460"
730 HREF="#FTN.AEN19460"
731 >[1]</A
732 >
733
734 It is often useful to trap the
735 <I
736 CLASS="FIRSTTERM"
737 >exit</I
738 >, forcing a <SPAN
739 CLASS="QUOTE"
740 >"printout"</SPAN
741 >
742 of variables, for example. The <I
743 CLASS="FIRSTTERM"
744 >trap</I
745 >
746 must be the first command in the script.</P
747 ></LI
748 ></OL
749 >
750 </P
751 ><DIV
752 CLASS="VARIABLELIST"
753 ><P
754 ><B
755 ><A
756 NAME="TRAPREF1"
757 ></A
758 >Trapping signals</B
759 ></P
760 ><DL
761 ><DT
762 ><B
763 CLASS="COMMAND"
764 >trap</B
765 ></DT
766 ><DD
767 ><P
768 >Specifies an action on receipt of a
769 signal; also useful for debugging.</P
770 ><P
771 ><A
772 NAME="SIGNALD"
773 ></A
774 ></P
775 ><TABLE
776 CLASS="SIDEBAR"
777 BORDER="1"
778 CELLPADDING="5"
779 ><TR
780 ><TD
781 ><DIV
782 CLASS="SIDEBAR"
783 ><A
784 NAME="AEN19477"
785 ></A
786 ><P
787 >A <I
788 CLASS="FIRSTTERM"
789 >signal</I
790 > is a message
791 sent to a process, either by the kernel or another
792 process, telling it to take some specified action
793 (usually to terminate). For example, hitting a
794 <A
795 HREF="special-chars.html#CTLCREF"
796 >Control-C</A
797 >
798 sends a user interrupt, an INT signal, to a running
799 program.</P
800 ></DIV
801 ></TD
802 ></TR
803 ></TABLE
804 ><P
805 ><SPAN
806 CLASS="emphasis"
807 ><I
808 CLASS="EMPHASIS"
809 >A simple instance:</I
810 ></SPAN
811 >
812 <TABLE
813 BORDER="0"
814 BGCOLOR="#E0E0E0"
815 WIDTH="90%"
816 ><TR
817 ><TD
818 ><PRE
819 CLASS="PROGRAMLISTING"
820 > 1&nbsp;trap '' 2
821 2&nbsp;# Ignore interrupt 2 (Control-C), with no action specified.
822 3&nbsp;
823 4&nbsp;trap 'echo "Control-C disabled."' 2
824 5&nbsp;# Message when Control-C pressed.</PRE
825 ></TD
826 ></TR
827 ></TABLE
828 >
829 </P
830 ></DD
831 ></DL
832 ></DIV
833 ><DIV
834 CLASS="EXAMPLE"
835 ><HR><A
836 NAME="EX76"
837 ></A
838 ><P
839 ><B
840 >Example 32-5. Trapping at exit</B
841 ></P
842 ><TABLE
843 BORDER="0"
844 BGCOLOR="#E0E0E0"
845 WIDTH="100%"
846 ><TR
847 ><TD
848 ><PRE
849 CLASS="PROGRAMLISTING"
850 > 1&nbsp;#!/bin/bash
851 2&nbsp;# Hunting variables with a trap.
852 3&nbsp;
853 4&nbsp;trap 'echo Variable Listing --- a = $a b = $b' EXIT
854 5&nbsp;# EXIT is the name of the signal generated upon exit from a script.
855 6&nbsp;#
856 7&nbsp;# The command specified by the "trap" doesn't execute until
857 8&nbsp;#+ the appropriate signal is sent.
858 9&nbsp;
859 10&nbsp;echo "This prints before the \"trap\" --"
860 11&nbsp;echo "even though the script sees the \"trap\" first."
861 12&nbsp;echo
862 13&nbsp;
863 14&nbsp;a=39
864 15&nbsp;
865 16&nbsp;b=36
866 17&nbsp;
867 18&nbsp;exit 0
868 19&nbsp;# Note that commenting out the 'exit' command makes no difference,
869 20&nbsp;#+ since the script exits in any case after running out of commands.</PRE
870 ></TD
871 ></TR
872 ></TABLE
873 ><HR></DIV
874 ><DIV
875 CLASS="EXAMPLE"
876 ><HR><A
877 NAME="ONLINE"
878 ></A
879 ><P
880 ><B
881 >Example 32-6. Cleaning up after <B
882 CLASS="KEYCAP"
883 >Control-C</B
884 ></B
885 ></P
886 ><TABLE
887 BORDER="0"
888 BGCOLOR="#E0E0E0"
889 WIDTH="100%"
890 ><TR
891 ><TD
892 ><PRE
893 CLASS="PROGRAMLISTING"
894 > 1&nbsp;#!/bin/bash
895 2&nbsp;# logon.sh: A quick 'n dirty script to check whether you are on-line yet.
896 3&nbsp;
897 4&nbsp;umask 177 # Make sure temp files are not world readable.
898 5&nbsp;
899 6&nbsp;
900 7&nbsp;TRUE=1
901 8&nbsp;LOGFILE=/var/log/messages
902 9&nbsp;# Note that $LOGFILE must be readable
903 10&nbsp;#+ (as root, chmod 644 /var/log/messages).
904 11&nbsp;TEMPFILE=temp.$$
905 12&nbsp;# Create a "unique" temp file name, using process id of the script.
906 13&nbsp;# Using 'mktemp' is an alternative.
907 14&nbsp;# For example:
908 15&nbsp;# TEMPFILE=`mktemp temp.XXXXXX`
909 16&nbsp;KEYWORD=address
910 17&nbsp;# At logon, the line "remote IP address xxx.xxx.xxx.xxx"
911 18&nbsp;# appended to /var/log/messages.
912 19&nbsp;ONLINE=22
913 20&nbsp;USER_INTERRUPT=13
914 21&nbsp;CHECK_LINES=100
915 22&nbsp;# How many lines in log file to check.
916 23&nbsp;
917 24&nbsp;trap 'rm -f $TEMPFILE; exit $USER_INTERRUPT' TERM INT
918 25&nbsp;# Cleans up the temp file if script interrupted by control-c.
919 26&nbsp;
920 27&nbsp;echo
921 28&nbsp;
922 29&nbsp;while [ $TRUE ] #Endless loop.
923 30&nbsp;do
924 31&nbsp; tail -n $CHECK_LINES $LOGFILE&#62; $TEMPFILE
925 32&nbsp; # Saves last 100 lines of system log file as temp file.
926 33&nbsp; # Necessary, since newer kernels generate many log messages at log on.
927 34&nbsp; search=`grep $KEYWORD $TEMPFILE`
928 35&nbsp; # Checks for presence of the "IP address" phrase,
929 36&nbsp; #+ indicating a successful logon.
930 37&nbsp;
931 38&nbsp; if [ ! -z "$search" ] # Quotes necessary because of possible spaces.
932 39&nbsp; then
933 40&nbsp; echo "On-line"
934 41&nbsp; rm -f $TEMPFILE # Clean up temp file.
935 42&nbsp; exit $ONLINE
936 43&nbsp; else
937 44&nbsp; echo -n "." # The -n option to echo suppresses newline,
938 45&nbsp; #+ so you get continuous rows of dots.
939 46&nbsp; fi
940 47&nbsp;
941 48&nbsp; sleep 1
942 49&nbsp;done
943 50&nbsp;
944 51&nbsp;
945 52&nbsp;# Note: if you change the KEYWORD variable to "Exit",
946 53&nbsp;#+ this script can be used while on-line
947 54&nbsp;#+ to check for an unexpected logoff.
948 55&nbsp;
949 56&nbsp;# Exercise: Change the script, per the above note,
950 57&nbsp;# and prettify it.
951 58&nbsp;
952 59&nbsp;exit 0
953 60&nbsp;
954 61&nbsp;
955 62&nbsp;# Nick Drage suggests an alternate method:
956 63&nbsp;
957 64&nbsp;while true
958 65&nbsp; do ifconfig ppp0 | grep UP 1&#62; /dev/null &#38;&#38; echo "connected" &#38;&#38; exit 0
959 66&nbsp; echo -n "." # Prints dots (.....) until connected.
960 67&nbsp; sleep 2
961 68&nbsp;done
962 69&nbsp;
963 70&nbsp;# Problem: Hitting Control-C to terminate this process may be insufficient.
964 71&nbsp;#+ (Dots may keep on echoing.)
965 72&nbsp;# Exercise: Fix this.
966 73&nbsp;
967 74&nbsp;
968 75&nbsp;
969 76&nbsp;# Stephane Chazelas has yet another alternative:
970 77&nbsp;
971 78&nbsp;CHECK_INTERVAL=1
972 79&nbsp;
973 80&nbsp;while ! tail -n 1 "$LOGFILE" | grep -q "$KEYWORD"
974 81&nbsp;do echo -n .
975 82&nbsp; sleep $CHECK_INTERVAL
976 83&nbsp;done
977 84&nbsp;echo "On-line"
978 85&nbsp;
979 86&nbsp;# Exercise: Discuss the relative strengths and weaknesses
980 87&nbsp;# of each of these various approaches.</PRE
981 ></TD
982 ></TR
983 ></TABLE
984 ><HR></DIV
985 ><DIV
986 CLASS="EXAMPLE"
987 ><HR><A
988 NAME="PROGRESSBAR2"
989 ></A
990 ><P
991 ><B
992 >Example 32-7. A Simple Implementation of a Progress Bar</B
993 ></P
994 ><TABLE
995 BORDER="0"
996 BGCOLOR="#E0E0E0"
997 WIDTH="100%"
998 ><TR
999 ><TD
1000 ><PRE
1001 CLASS="PROGRAMLISTING"
1002 > 1&nbsp;#! /bin/bash
1003 2&nbsp;# progress-bar2.sh
1004 3&nbsp;# Author: Graham Ewart (with reformatting by ABS Guide author).
1005 4&nbsp;# Used in ABS Guide with permission (thanks!).
1006 5&nbsp;
1007 6&nbsp;# Invoke this script with bash. It doesn't work with sh.
1008 7&nbsp;
1009 8&nbsp;interval=1
1010 9&nbsp;long_interval=10
1011 10&nbsp;
1012 11&nbsp;{
1013 12&nbsp; trap "exit" SIGUSR1
1014 13&nbsp; sleep $interval; sleep $interval
1015 14&nbsp; while true
1016 15&nbsp; do
1017 16&nbsp; echo -n '.' # Use dots.
1018 17&nbsp; sleep $interval
1019 18&nbsp; done; } &#38; # Start a progress bar as a background process.
1020 19&nbsp;
1021 20&nbsp;pid=$!
1022 21&nbsp;trap "echo !; kill -USR1 $pid; wait $pid" EXIT # To handle ^C.
1023 22&nbsp;
1024 23&nbsp;echo -n 'Long-running process '
1025 24&nbsp;sleep $long_interval
1026 25&nbsp;echo ' Finished!'
1027 26&nbsp;
1028 27&nbsp;kill -USR1 $pid
1029 28&nbsp;wait $pid # Stop the progress bar.
1030 29&nbsp;trap EXIT
1031 30&nbsp;
1032 31&nbsp;exit $?</PRE
1033 ></TD
1034 ></TR
1035 ></TABLE
1036 ><HR></DIV
1037 ><DIV
1038 CLASS="NOTE"
1039 ><TABLE
1040 CLASS="NOTE"
1041 WIDTH="100%"
1042 BORDER="0"
1043 ><TR
1044 ><TD
1045 WIDTH="25"
1046 ALIGN="CENTER"
1047 VALIGN="TOP"
1048 ><IMG
1049 SRC="common/note.png"
1050 HSPACE="5"
1051 ALT="Note"></TD
1052 ><TD
1053 ALIGN="LEFT"
1054 VALIGN="TOP"
1055 ><P
1056 >The <TT
1057 CLASS="OPTION"
1058 >DEBUG</TT
1059 > argument to
1060 <B
1061 CLASS="COMMAND"
1062 >trap</B
1063 > causes a specified action to execute
1064 after every command in a script. This permits tracing variables,
1065 for example.
1066
1067 <DIV
1068 CLASS="EXAMPLE"
1069 ><HR><A
1070 NAME="VARTRACE"
1071 ></A
1072 ><P
1073 ><B
1074 >Example 32-8. Tracing a variable</B
1075 ></P
1076 ><TABLE
1077 BORDER="0"
1078 BGCOLOR="#E0E0E0"
1079 WIDTH="100%"
1080 ><TR
1081 ><TD
1082 ><PRE
1083 CLASS="PROGRAMLISTING"
1084 > 1&nbsp;#!/bin/bash
1085 2&nbsp;
1086 3&nbsp;trap 'echo "VARIABLE-TRACE&#62; \$variable = \"$variable\""' DEBUG
1087 4&nbsp;# Echoes the value of $variable after every command.
1088 5&nbsp;
1089 6&nbsp;variable=29; line=$LINENO
1090 7&nbsp;
1091 8&nbsp;echo " Just initialized \$variable to $variable in line number $line."
1092 9&nbsp;
1093 10&nbsp;let "variable *= 3"; line=$LINENO
1094 11&nbsp;echo " Just multiplied \$variable by 3 in line number $line."
1095 12&nbsp;
1096 13&nbsp;exit 0
1097 14&nbsp;
1098 15&nbsp;# The "trap 'command1 . . . command2 . . .' DEBUG" construct is
1099 16&nbsp;#+ more appropriate in the context of a complex script,
1100 17&nbsp;#+ where inserting multiple "echo $variable" statements might be
1101 18&nbsp;#+ awkward and time-consuming.
1102 19&nbsp;
1103 20&nbsp;# Thanks, Stephane Chazelas for the pointer.
1104 21&nbsp;
1105 22&nbsp;
1106 23&nbsp;Output of script:
1107 24&nbsp;
1108 25&nbsp;VARIABLE-TRACE&#62; $variable = ""
1109 26&nbsp;VARIABLE-TRACE&#62; $variable = "29"
1110 27&nbsp; Just initialized $variable to 29.
1111 28&nbsp;VARIABLE-TRACE&#62; $variable = "29"
1112 29&nbsp;VARIABLE-TRACE&#62; $variable = "87"
1113 30&nbsp; Just multiplied $variable by 3.
1114 31&nbsp;VARIABLE-TRACE&#62; $variable = "87"</PRE
1115 ></TD
1116 ></TR
1117 ></TABLE
1118 ><HR></DIV
1119 >
1120
1121 </P
1122 ></TD
1123 ></TR
1124 ></TABLE
1125 ></DIV
1126 ><P
1127 >Of course, the <B
1128 CLASS="COMMAND"
1129 >trap</B
1130 > command has other uses
1131 aside from debugging, such as disabling certain keystrokes within a
1132 script (see <A
1133 HREF="contributed-scripts.html#STOPWATCH"
1134 >Example A-43</A
1135 >).</P
1136 ><DIV
1137 CLASS="EXAMPLE"
1138 ><HR><A
1139 NAME="MULTIPLEPROC"
1140 ></A
1141 ><P
1142 ><B
1143 >Example 32-9. Running multiple processes (on an SMP box)</B
1144 ></P
1145 ><TABLE
1146 BORDER="0"
1147 BGCOLOR="#E0E0E0"
1148 WIDTH="100%"
1149 ><TR
1150 ><TD
1151 ><PRE
1152 CLASS="PROGRAMLISTING"
1153 > 1&nbsp;#!/bin/bash
1154 2&nbsp;# parent.sh
1155 3&nbsp;# Running multiple processes on an SMP box.
1156 4&nbsp;# Author: Tedman Eng
1157 5&nbsp;
1158 6&nbsp;# This is the first of two scripts,
1159 7&nbsp;#+ both of which must be present in the current working directory.
1160 8&nbsp;
1161 9&nbsp;
1162 10&nbsp;
1163 11&nbsp;
1164 12&nbsp;LIMIT=$1 # Total number of process to start
1165 13&nbsp;NUMPROC=4 # Number of concurrent threads (forks?)
1166 14&nbsp;PROCID=1 # Starting Process ID
1167 15&nbsp;echo "My PID is $$"
1168 16&nbsp;
1169 17&nbsp;function start_thread() {
1170 18&nbsp; if [ $PROCID -le $LIMIT ] ; then
1171 19&nbsp; ./child.sh $PROCID&#38;
1172 20&nbsp; let "PROCID++"
1173 21&nbsp; else
1174 22&nbsp; echo "Limit reached."
1175 23&nbsp; wait
1176 24&nbsp; exit
1177 25&nbsp; fi
1178 26&nbsp;}
1179 27&nbsp;
1180 28&nbsp;while [ "$NUMPROC" -gt 0 ]; do
1181 29&nbsp; start_thread;
1182 30&nbsp; let "NUMPROC--"
1183 31&nbsp;done
1184 32&nbsp;
1185 33&nbsp;
1186 34&nbsp;while true
1187 35&nbsp;do
1188 36&nbsp;
1189 37&nbsp;trap "start_thread" SIGRTMIN
1190 38&nbsp;
1191 39&nbsp;done
1192 40&nbsp;
1193 41&nbsp;exit 0
1194 42&nbsp;
1195 43&nbsp;
1196 44&nbsp;
1197 45&nbsp;# ======== Second script follows ========
1198 46&nbsp;
1199 47&nbsp;
1200 48&nbsp;#!/bin/bash
1201 49&nbsp;# child.sh
1202 50&nbsp;# Running multiple processes on an SMP box.
1203 51&nbsp;# This script is called by parent.sh.
1204 52&nbsp;# Author: Tedman Eng
1205 53&nbsp;
1206 54&nbsp;temp=$RANDOM
1207 55&nbsp;index=$1
1208 56&nbsp;shift
1209 57&nbsp;let "temp %= 5"
1210 58&nbsp;let "temp += 4"
1211 59&nbsp;echo "Starting $index Time:$temp" "$@"
1212 60&nbsp;sleep ${temp}
1213 61&nbsp;echo "Ending $index"
1214 62&nbsp;kill -s SIGRTMIN $PPID
1215 63&nbsp;
1216 64&nbsp;exit 0
1217 65&nbsp;
1218 66&nbsp;
1219 67&nbsp;# ======================= SCRIPT AUTHOR'S NOTES ======================= #
1220 68&nbsp;# It's not completely bug free.
1221 69&nbsp;# I ran it with limit = 500 and after the first few hundred iterations,
1222 70&nbsp;#+ one of the concurrent threads disappeared!
1223 71&nbsp;# Not sure if this is collisions from trap signals or something else.
1224 72&nbsp;# Once the trap is received, there's a brief moment while executing the
1225 73&nbsp;#+ trap handler but before the next trap is set. During this time, it may
1226 74&nbsp;#+ be possible to miss a trap signal, thus miss spawning a child process.
1227 75&nbsp;
1228 76&nbsp;# No doubt someone may spot the bug and will be writing
1229 77&nbsp;#+ . . . in the future.
1230 78&nbsp;
1231 79&nbsp;
1232 80&nbsp;
1233 81&nbsp;# ===================================================================== #
1234 82&nbsp;
1235 83&nbsp;
1236 84&nbsp;
1237 85&nbsp;# ----------------------------------------------------------------------#
1238 86&nbsp;
1239 87&nbsp;
1240 88&nbsp;
1241 89&nbsp;#################################################################
1242 90&nbsp;# The following is the original script written by Vernia Damiano.
1243 91&nbsp;# Unfortunately, it doesn't work properly.
1244 92&nbsp;#################################################################
1245 93&nbsp;
1246 94&nbsp;#!/bin/bash
1247 95&nbsp;
1248 96&nbsp;# Must call script with at least one integer parameter
1249 97&nbsp;#+ (number of concurrent processes).
1250 98&nbsp;# All other parameters are passed through to the processes started.
1251 99&nbsp;
1252 100&nbsp;
1253 101&nbsp;INDICE=8 # Total number of process to start
1254 102&nbsp;TEMPO=5 # Maximum sleep time per process
1255 103&nbsp;E_BADARGS=65 # No arg(s) passed to script.
1256 104&nbsp;
1257 105&nbsp;if [ $# -eq 0 ] # Check for at least one argument passed to script.
1258 106&nbsp;then
1259 107&nbsp; echo "Usage: `basename $0` number_of_processes [passed params]"
1260 108&nbsp; exit $E_BADARGS
1261 109&nbsp;fi
1262 110&nbsp;
1263 111&nbsp;NUMPROC=$1 # Number of concurrent process
1264 112&nbsp;shift
1265 113&nbsp;PARAMETRI=( "$@" ) # Parameters of each process
1266 114&nbsp;
1267 115&nbsp;function avvia() {
1268 116&nbsp; local temp
1269 117&nbsp; local index
1270 118&nbsp; temp=$RANDOM
1271 119&nbsp; index=$1
1272 120&nbsp; shift
1273 121&nbsp; let "temp %= $TEMPO"
1274 122&nbsp; let "temp += 1"
1275 123&nbsp; echo "Starting $index Time:$temp" "$@"
1276 124&nbsp; sleep ${temp}
1277 125&nbsp; echo "Ending $index"
1278 126&nbsp; kill -s SIGRTMIN $$
1279 127&nbsp;}
1280 128&nbsp;
1281 129&nbsp;function parti() {
1282 130&nbsp; if [ $INDICE -gt 0 ] ; then
1283 131&nbsp; avvia $INDICE "${PARAMETRI[@]}" &#38;
1284 132&nbsp; let "INDICE--"
1285 133&nbsp; else
1286 134&nbsp; trap : SIGRTMIN
1287 135&nbsp; fi
1288 136&nbsp;}
1289 137&nbsp;
1290 138&nbsp;trap parti SIGRTMIN
1291 139&nbsp;
1292 140&nbsp;while [ "$NUMPROC" -gt 0 ]; do
1293 141&nbsp; parti;
1294 142&nbsp; let "NUMPROC--"
1295 143&nbsp;done
1296 144&nbsp;
1297 145&nbsp;wait
1298 146&nbsp;trap - SIGRTMIN
1299 147&nbsp;
1300 148&nbsp;exit $?
1301 149&nbsp;
1302 150&nbsp;: &#60;&#60;SCRIPT_AUTHOR_COMMENTS
1303 151&nbsp;I had the need to run a program, with specified options, on a number of
1304 152&nbsp;different files, using a SMP machine. So I thought [I'd] keep running
1305 153&nbsp;a specified number of processes and start a new one each time . . . one
1306 154&nbsp;of these terminates.
1307 155&nbsp;
1308 156&nbsp;The "wait" instruction does not help, since it waits for a given process
1309 157&nbsp;or *all* process started in background. So I wrote [this] bash script
1310 158&nbsp;that can do the job, using the "trap" instruction.
1311 159&nbsp; --Vernia Damiano
1312 160&nbsp;SCRIPT_AUTHOR_COMMENTS</PRE
1313 ></TD
1314 ></TR
1315 ></TABLE
1316 ><HR></DIV
1317 ><DIV
1318 CLASS="NOTE"
1319 ><TABLE
1320 CLASS="NOTE"
1321 WIDTH="100%"
1322 BORDER="0"
1323 ><TR
1324 ><TD
1325 WIDTH="25"
1326 ALIGN="CENTER"
1327 VALIGN="TOP"
1328 ><IMG
1329 SRC="common/note.png"
1330 HSPACE="5"
1331 ALT="Note"></TD
1332 ><TD
1333 ALIGN="LEFT"
1334 VALIGN="TOP"
1335 ><P
1336 ><TT
1337 CLASS="USERINPUT"
1338 ><B
1339 >trap '' SIGNAL</B
1340 ></TT
1341 > (two adjacent
1342 apostrophes) disables SIGNAL for the remainder of the
1343 script. <TT
1344 CLASS="USERINPUT"
1345 ><B
1346 >trap SIGNAL</B
1347 ></TT
1348 > restores
1349 the functioning of SIGNAL once more. This is useful to
1350 protect a critical portion of a script from an undesirable
1351 interrupt.</P
1352 ></TD
1353 ></TR
1354 ></TABLE
1355 ></DIV
1356 ><P
1357 ><TABLE
1358 BORDER="0"
1359 BGCOLOR="#E0E0E0"
1360 WIDTH="100%"
1361 ><TR
1362 ><TD
1363 ><PRE
1364 CLASS="PROGRAMLISTING"
1365 > 1&nbsp; trap '' 2 # Signal 2 is Control-C, now disabled.
1366 2&nbsp; command
1367 3&nbsp; command
1368 4&nbsp; command
1369 5&nbsp; trap 2 # Reenables Control-C
1370 6&nbsp; </PRE
1371 ></TD
1372 ></TR
1373 ></TABLE
1374 ></P
1375 ><TABLE
1376 CLASS="SIDEBAR"
1377 BORDER="1"
1378 CELLPADDING="5"
1379 ><TR
1380 ><TD
1381 ><DIV
1382 CLASS="SIDEBAR"
1383 ><A
1384 NAME="AEN19513"
1385 ></A
1386 ><P
1387 ><A
1388 HREF="bashver3.html#BASH3REF"
1389 >Version 3</A
1390 > of Bash adds the
1391 following <A
1392 HREF="variables2.html#INTERNALVARIABLES1"
1393 >internal
1394 variables</A
1395 > for use by the debugger.
1396
1397 <OL
1398 TYPE="1"
1399 ><LI
1400 ><P
1401 ><TT
1402 CLASS="VARNAME"
1403 >$BASH_ARGC</TT
1404 ></P
1405 ><P
1406 >Number of command-line arguments passed to script,
1407 similar to <A
1408 HREF="variables2.html#CLACOUNTREF"
1409 ><TT
1410 CLASS="VARNAME"
1411 >$#</TT
1412 ></A
1413 >.</P
1414 ></LI
1415 ><LI
1416 ><P
1417 ><TT
1418 CLASS="VARNAME"
1419 >$BASH_ARGV</TT
1420 ></P
1421 ><P
1422 >Final command-line parameter passed to script, equivalent
1423 <A
1424 HREF="othertypesv.html#LASTARGREF"
1425 ><TT
1426 CLASS="VARNAME"
1427 >${!#}</TT
1428 ></A
1429 >.</P
1430 ></LI
1431 ><LI
1432 ><P
1433 ><TT
1434 CLASS="VARNAME"
1435 >$BASH_COMMAND</TT
1436 ></P
1437 ><P
1438 >Command currently executing.</P
1439 ></LI
1440 ><LI
1441 ><P
1442 ><TT
1443 CLASS="VARNAME"
1444 >$BASH_EXECUTION_STRING</TT
1445 ></P
1446 ><P
1447 >The <I
1448 CLASS="FIRSTTERM"
1449 >option string</I
1450 > following the
1451 <TT
1452 CLASS="OPTION"
1453 >-c</TT
1454 > <A
1455 HREF="bash-options.html#CLOPTS"
1456 >option</A
1457 >
1458 to Bash.</P
1459 ></LI
1460 ><LI
1461 ><P
1462 ><TT
1463 CLASS="VARNAME"
1464 >$BASH_LINENO</TT
1465 ></P
1466 ><P
1467 >In a <A
1468 HREF="functions.html#FUNCTIONREF"
1469 >function</A
1470 >,
1471 indicates the line number of the function call.</P
1472 ></LI
1473 ><LI
1474 ><P
1475 ><TT
1476 CLASS="VARNAME"
1477 >$BASH_REMATCH</TT
1478 ></P
1479 ><P
1480 >Array variable associated with <B
1481 CLASS="COMMAND"
1482 >=~</B
1483 >
1484 <A
1485 HREF="bashver3.html#REGEXMATCHREF"
1486 >conditional regex
1487 matching</A
1488 >.</P
1489 ></LI
1490 ><LI
1491 ><P
1492 ><A
1493 NAME="BASHSOURCEREF"
1494 ></A
1495 ></P
1496 ><P
1497 ><TT
1498 CLASS="VARNAME"
1499 >$BASH_SOURCE</TT
1500 ></P
1501 ><P
1502 >This is the name of the script, usually the same as
1503 <A
1504 HREF="othertypesv.html#ARG0"
1505 >$0</A
1506 >.</P
1507 ></LI
1508 ><LI
1509 ><P
1510 > <A
1511 HREF="variables2.html#BASHSUBSHELLREF"
1512 ><TT
1513 CLASS="VARNAME"
1514 >$BASH_SUBSHELL</TT
1515 ></A
1516 ></P
1517 ></LI
1518 ></OL
1519 ></P
1520 ></DIV
1521 ></TD
1522 ></TR
1523 ></TABLE
1524 ></DIV
1525 ><H3
1526 CLASS="FOOTNOTES"
1527 >Notes</H3
1528 ><TABLE
1529 BORDER="0"
1530 CLASS="FOOTNOTES"
1531 WIDTH="100%"
1532 ><TR
1533 ><TD
1534 ALIGN="LEFT"
1535 VALIGN="TOP"
1536 WIDTH="5%"
1537 ><A
1538 NAME="FTN.AEN19460"
1539 HREF="debugging.html#AEN19460"
1540 >[1]</A
1541 ></TD
1542 ><TD
1543 ALIGN="LEFT"
1544 VALIGN="TOP"
1545 WIDTH="95%"
1546 ><P
1547 >By convention, <TT
1548 CLASS="REPLACEABLE"
1549 ><I
1550 >signal
1551 0</I
1552 ></TT
1553 > is assigned to <A
1554 HREF="exit-status.html#EXITCOMMANDREF"
1555 >exit</A
1556 >. </P
1557 ></TD
1558 ></TR
1559 ></TABLE
1560 ><DIV
1561 CLASS="NAVFOOTER"
1562 ><HR
1563 ALIGN="LEFT"
1564 WIDTH="100%"><TABLE
1565 SUMMARY="Footer navigation table"
1566 WIDTH="100%"
1567 BORDER="0"
1568 CELLPADDING="0"
1569 CELLSPACING="0"
1570 ><TR
1571 ><TD
1572 WIDTH="33%"
1573 ALIGN="left"
1574 VALIGN="top"
1575 ><A
1576 HREF="zeros.html"
1577 ACCESSKEY="P"
1578 >Prev</A
1579 ></TD
1580 ><TD
1581 WIDTH="34%"
1582 ALIGN="center"
1583 VALIGN="top"
1584 ><A
1585 HREF="index.html"
1586 ACCESSKEY="H"
1587 >Home</A
1588 ></TD
1589 ><TD
1590 WIDTH="33%"
1591 ALIGN="right"
1592 VALIGN="top"
1593 ><A
1594 HREF="options.html"
1595 ACCESSKEY="N"
1596 >Next</A
1597 ></TD
1598 ></TR
1599 ><TR
1600 ><TD
1601 WIDTH="33%"
1602 ALIGN="left"
1603 VALIGN="top"
1604 >Of Zeros and Nulls</TD
1605 ><TD
1606 WIDTH="34%"
1607 ALIGN="center"
1608 VALIGN="top"
1609 ><A
1610 HREF="part5.html"
1611 ACCESSKEY="U"
1612 >Up</A
1613 ></TD
1614 ><TD
1615 WIDTH="33%"
1616 ALIGN="right"
1617 VALIGN="top"
1618 >Options</TD
1619 ></TR
1620 ></TABLE
1621 ></DIV
1622 ></BODY
1623 ></HTML
1624 >