Skip to content

Commit 70b733f

Browse files
Add exit codes 128+
1 parent df8cba2 commit 70b733f

File tree

3 files changed

+86
-22
lines changed

3 files changed

+86
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ touch_format "Foo 2021-05-04 22:57:54 Goo"
443443
444444
Get a string's characters that match a class, with optional offset and length.
445445
446-
Syntax:
446+
Syntax:
447447
448448
```sh
449449
select_character_class <string> <class> [offset [length]]
@@ -474,7 +474,7 @@ select_character_class foo123goo456 alpha 3 1
474474
475475
Get a string's characters that don't match a class, with optional offset and length.
476476
477-
Syntax:
477+
Syntax:
478478
479479
```sh
480480
reject_character_class <string> <class> [offset [length]]

doc/exit-codes/index.md

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,39 @@ Conventions:
1212

1313
* 3-63 are for a program-specific exit codes.
1414

15-
* 64-78 are based on sysexits documentation from the 1980's.
15+
* 64-78 are based on BSD sysexits <https://man.openbsd.org/sysexits.3>
1616

1717
* 80-119 are SixArm conventions that we find useful in many programs.
1818

19-
Many POSIX shells use exit codes 126 and 127 to signal specific error status:
19+
Many shells use exit codes 126-128 to signal specific error status:
2020

21-
* 126 is for the shell and indicates command found but not executable.
21+
* 126 is for the shell and indicates command found but is not executable.
2222

2323
* 127 is for the shell and indicate command not found.
2424

25-
Many POSIX shells use exit codes above 128 in their $? representation of the
25+
* 128 is for invalid argument to exit.
26+
27+
Many shells use exit codes above 128 in their $? representation of the
2628
exit status to encode the signal number of a process being killed.
2729

28-
The pre-defined exit codes from sysexits can be used, so the caller of the
29-
process can get a rough estimation about the failure class without looking up
30-
the source code.
30+
* 128+n means fatal error signal "n"
31+
32+
* Example: 130 means terminated by ctrl-c (because ctrl-c is signal 2)
33+
34+
* Example: 137 means terminated by kill -9 (because 128 + 9 = 137)
35+
36+
Finally, the highest exit code:
37+
38+
* 255 Exit status out of range (exit takes integer args 0-255)
39+
40+
Be aware that on some shells, ut of range exit values can result in unexpected
41+
exit codes. An exit value greater than 255 returns an exit code modulo 256.
3142

32-
See https://man.openbsd.org/sysexits.3
43+
* Example: exit 257 becomes exit 1 (because 257 % 256 = 1)
3344

34-
The exit codes in our list can be useful for a variety of needs, such as:
45+
* Caution: exit 256 becomes exit 0, which probably isn't what you want.
46+
47+
For some typical needs that we encounter, we can suggest these:
3548

3649
* Authentication issues: `exit $EXIT_NOUSER`
3750

@@ -444,3 +457,25 @@ EXIT_COMMAND_NOT_FOUND=127
444457
```
445458

446459
A command is not found.
460+
461+
462+
### Exit code invalid
463+
464+
```sh
465+
EXIT_CODE_INVALID=128
466+
```
467+
468+
The exit code is invalid.
469+
470+
Compare EXIT_CODE_OUT_OF_RANGE=255
471+
472+
473+
### Exit code out of range
474+
475+
```sh
476+
EXIT_CODE_INVALID=128
477+
```
478+
479+
The exit code is out of range i.e. not in 0-255.
480+
481+
Compare EXIT_CODE_INVALID=128

posix-shell-script-kit

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,26 +58,39 @@
5858
#
5959
# * 3-63 are for a program-specific exit codes.
6060
#
61-
# * 64-78 are based on sysexits documentation from the 1980's.
61+
# * 64-78 are based on BSD sysexits <https://man.openbsd.org/sysexits.3>
6262
#
6363
# * 80-119 are SixArm conventions that we find useful in many programs.
6464
#
65-
# Many POSIX shells use exit codes 126 and 127 to signal specific error status:
65+
# Many shells use exit codes 126-128 to signal specific error status:
6666
#
67-
# * 126 is for the shell and indicates command found but not executable.
67+
# * 126 is for the shell and indicates command found but is not executable.
6868
#
6969
# * 127 is for the shell and indicate command not found.
7070
#
71-
# Many POSIX shells use exit codes above 128 in their $? representation of the
72-
# exit status to encode the signal number of a process being killed.
71+
# * 128 is for invalid argument to exit.
7372
#
74-
# The pre-defined exit codes from sysexits can be used, so the caller of the
75-
# process can get a rough estimation about the failure class without looking up
76-
# the source code.
73+
# Many shells use exit codes above 128 in their $? representation of the exit
74+
# status to encode the signal number of a process being killed.
7775
#
78-
# See https://man.openbsd.org/sysexits.3
76+
# * 128+n means fatal error signal "n"
7977
#
80-
# We recommend:
78+
# * Example: 130 means terminated by ctrl-C (because ctrl-c is signal 2)
79+
#
80+
# * Example: 137 means terminated by kill -9 (because 128 + 9 = 137)
81+
#
82+
# Finally, the highest exit code:
83+
#
84+
# * 255 Exit status out of range (exit takes integer args 0-255)
85+
#
86+
# Be aware that on some shells, ut of range exit values can result in unexpected
87+
# exit codes. An exit value greater than 255 returns an exit code modulo 256.
88+
#
89+
# * Example: exit 257 becomes exit 1 (because 257 % 256 = 1)
90+
#
91+
# * Caution: exit 256 becomes exit 0, which probably isn't what you want.
92+
#
93+
# For some typical needs that we encounter, we can suggest these:
8194
#
8295
# * Authentication issues: exit $EXIT_NOUSER
8396
#
@@ -380,6 +393,22 @@ EXIT_COMMAND_FOUND_BUT_NOT_EXECUTABLE=126
380393
#
381394
EXIT_COMMAND_NOT_FOUND=127
382395

396+
# Exit code invalid
397+
#
398+
# The exit code is invalid.
399+
#
400+
# Compare EXIT_CODE_OUT_OF_RANGE=255
401+
#
402+
EXIT_CODE_INVALID=128
403+
404+
# Exit code out of range
405+
#
406+
# The exit code is out of range i.e. not in 0-255.
407+
#
408+
# Compare EXIT_CODE_INVALID=128
409+
#
410+
EXIT_CODE_INVALID=128
411+
383412
##
384413
# Input/output helpers
385414
##
@@ -967,7 +996,7 @@ touch_format() {
967996

968997
# select_character_class: get a string's characters that match a class, with optional offset and length.
969998
#
970-
# Syntax:
999+
# Syntax:
9711000
# ```
9721001
# select_character_class <string> <class> [offset [length]]
9731002
# ```

0 commit comments

Comments
 (0)