File: exitcodes.html

package info (click to toggle)
abs-guide 10-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 6,952 kB
  • sloc: sh: 14,129; makefile: 81
file content (634 lines) | stat: -rw-r--r-- 9,529 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML
><HEAD
><TITLE
>Exit Codes With Special Meanings</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="Advanced Bash-Scripting Guide"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Parsing and Managing Pathnames"
HREF="pathmanagement.html"><LINK
REL="NEXT"
TITLE="A Detailed Introduction to I/O and I/O Redirection"
HREF="ioredirintro.html"><META
HTTP-EQUIV="Content-Style-Type"
CONTENT="text/css"><LINK
REL="stylesheet"
HREF="common/kde-common.css"
TYPE="text/css"><META
HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1"><META
HTTP-EQUIV="Content-Language"
CONTENT="en"><LINK
REL="stylesheet"
HREF="common/kde-localised.css"
TYPE="text/css"
TITLE="KDE-English"><LINK
REL="stylesheet"
HREF="common/kde-default.css"
TYPE="text/css"
TITLE="KDE-Default"></HEAD
><BODY
CLASS="APPENDIX"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#AA0000"
VLINK="#AA0055"
ALINK="#AA0000"
STYLE="font-family: sans-serif;"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Advanced Bash-Scripting Guide: An in-depth exploration of the art of shell scripting</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="pathmanagement.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="ioredirintro.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="APPENDIX"
><H1
><A
NAME="EXITCODES"
></A
>Appendix E. Exit Codes With Special Meanings</H1
><P
><A
NAME="EXITCODESREF"
></A
></P
><DIV
CLASS="TABLE"
><HR><A
NAME="AEN23549"
></A
><P
><B
>Table E-1. <I
CLASS="FIRSTTERM"
>Reserved</I
> Exit Codes</B
></P
><TABLE
BORDER="1"
CLASS="CALSTABLE"
><THEAD
><TR
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Exit Code Number</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Meaning</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Example</TH
><TH
ALIGN="LEFT"
VALIGN="TOP"
>Comments</TH
></TR
></THEAD
><TBODY
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>1</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Catchall for general errors</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>let "var1 = 1/0"</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Miscellaneous errors, such as <SPAN
CLASS="QUOTE"
>"divide by
	        zero"</SPAN
> and other impermissible operations</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>2</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Misuse of shell builtins (according to Bash documentation)</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>empty_function() {}</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><A
HREF="debugging.html#MISSINGKEYWORD"
>Missing keyword</A
>
              or command, or permission problem (and <A
HREF="filearchiv.html#DIFFERR2"
><I
CLASS="FIRSTTERM"
>diff</I
> return code
	      on a failed binary file comparison</A
>).</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>126</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Command invoked cannot execute</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>/dev/null</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Permission problem or command is not an executable</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>127</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="QUOTE"
>"command not found"</SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>illegal_command</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Possible problem with <TT
CLASS="VARNAME"
>$PATH</TT
> or a typo</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>128</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Invalid argument to <A
HREF="exit-status.html#EXITCOMMANDREF"
>exit</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>exit 3.14159</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><B
CLASS="COMMAND"
>exit</B
> takes only integer args in the
		range <SPAN
CLASS="RETURNVALUE"
>0 - 255</SPAN
> (see
		first footnote)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>128+n</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Fatal error signal <SPAN
CLASS="QUOTE"
>"n"</SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><I
CLASS="FIRSTTERM"
>kill -9</I
> <TT
CLASS="VARNAME"
>$PPID</TT
> of script</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="USERINPUT"
><B
>$?</B
></TT
> returns
	      <SPAN
CLASS="ERRORCODE"
>137</SPAN
> (128 + 9)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>130</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Script terminated by Control-C</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>Ctl-C</I
></SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Control-C is fatal error signal
	      <SPAN
CLASS="ERRORCODE"
>2</SPAN
>, (130 = 128 + 2, see above)</TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
><TT
CLASS="OPTION"
>255*</TT
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>Exit status out of range</TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
>exit <SPAN
CLASS="RETURNVALUE"
>-1</SPAN
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><B
CLASS="COMMAND"
>exit</B
> takes only integer args in the
	        range <SPAN
CLASS="ERRORCODE"
>0 - 255</SPAN
></TD
></TR
></TBODY
></TABLE
><HR></DIV
><P
>According to the above table, exit codes <SPAN
CLASS="ERRORCODE"
>1 - 2,
        126 - 165, and 255</SPAN
>

	<A
NAME="AEN23629"
HREF="#FTN.AEN23629"
>[1]</A
>

	have special meanings, and should therefore be avoided for
	user-specified exit parameters. Ending a script with <I
CLASS="FIRSTTERM"
>exit
	127</I
> would certainly cause confusion when troubleshooting
	(is the error code a <SPAN
CLASS="QUOTE"
>"command not found"</SPAN
> or a
	user-defined one?). However, many scripts use an <I
CLASS="FIRSTTERM"
>exit
	1</I
> as a general bailout-upon-error. Since exit code
	<SPAN
CLASS="ERRORCODE"
>1</SPAN
> signifies so many possible errors,
	it is not particularly useful in debugging.</P
><P
><A
NAME="SYSEXITSREF"
></A
></P
><P
>There has been an attempt to systematize exit status numbers
	(see <TT
CLASS="FILENAME"
>/usr/include/sysexits.h</TT
>),
	but this is intended for C and C++ programmers. A similar
	standard for scripting might be appropriate. The author of
	this document proposes restricting user-defined exit codes to
	the range <SPAN
CLASS="RETURNVALUE"
>64 - 113</SPAN
> (in addition to
	<SPAN
CLASS="RETURNVALUE"
>0</SPAN
>, for success), to conform with
	the C/C++ standard. This would allot 50 valid codes, and make
	troubleshooting scripts more straightforward.
	  <A
NAME="AEN23647"
HREF="#FTN.AEN23647"
>[2]</A
>
	All user-defined exit codes in the accompanying examples to
	this document conform to this standard, except where overriding
	circumstances exist, as in <A
HREF="variables2.html#TMDIN"
>Example 9-2</A
>.</P
><DIV
CLASS="NOTE"
><TABLE
CLASS="NOTE"
WIDTH="100%"
BORDER="0"
><TR
><TD
WIDTH="25"
ALIGN="CENTER"
VALIGN="TOP"
><IMG
SRC="common/note.png"
HSPACE="5"
ALT="Note"></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
><P
>Issuing a <A
HREF="variables2.html#XSTATVARREF"
>$?</A
> from
	the command-line after a shell script exits gives
	results consistent with the table above only from the
	Bash or <I
CLASS="FIRSTTERM"
>sh</I
> prompt. Running the
	<I
CLASS="FIRSTTERM"
>C-shell</I
> or <I
CLASS="FIRSTTERM"
>tcsh</I
>
	may give different values in some cases.</P
></TD
></TR
></TABLE
></DIV
></DIV
><H3
CLASS="FOOTNOTES"
>Notes</H3
><TABLE
BORDER="0"
CLASS="FOOTNOTES"
WIDTH="100%"
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN23629"
HREF="exitcodes.html#AEN23629"
>[1]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
><A
NAME="EXCOOR"
></A
>Out of range exit values
	  can result in unexpected exit codes. An exit value
	  greater than <SPAN
CLASS="ERRORCODE"
>255</SPAN
> returns an
	  exit code <A
HREF="operations.html#MODULOREF"
>modulo</A
>
	  <SPAN
CLASS="ERRORCODE"
>256</SPAN
>. For example, <I
CLASS="FIRSTTERM"
>exit
	  3809</I
> gives an exit code of <SPAN
CLASS="ERRORCODE"
>225</SPAN
>
	  (3809 % 256 = 225).</P
></TD
></TR
><TR
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="5%"
><A
NAME="FTN.AEN23647"
HREF="exitcodes.html#AEN23647"
>[2]</A
></TD
><TD
ALIGN="LEFT"
VALIGN="TOP"
WIDTH="95%"
><P
>An update of <TT
CLASS="FILENAME"
>/usr/include/sysexits.h</TT
>
	  allocates previously unused exit codes from <SPAN
CLASS="RETURNVALUE"
>64
	  - 78</SPAN
>.  It may be anticipated that the range of
	  unallotted exit codes will be further restricted in the future.
	  The author of this document will <SPAN
CLASS="emphasis"
><I
CLASS="EMPHASIS"
>not</I
></SPAN
> do
	  fixups on the scripting examples to conform to the changing
	  standard. This should not cause any problems, since there
	  is no overlap or conflict in usage of exit codes between
	  compiled C/C++ binaries and shell scripts.</P
></TD
></TR
></TABLE
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="pathmanagement.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="ioredirintro.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Parsing and Managing Pathnames</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>A Detailed Introduction to I/O and I/O Redirection</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>