Predictive Hacks

Exit Status in Linux

In Linux, every command has an exit code that takes values from 0 to 255. What we should keep in mind is that 0 means success and anything else is an error. In order to get the exit code, we can run $?. For example, I will run the command wc

cat myscript.sh | wc

And if I want to get the exit code:

echo $?

And we get 0 which means success. Now, let’s say that we want to remove a file that does not exist.

rm non_exist_script.sh
echo $?

Here the exit code was 1 which means “not success” and more particularly it means operation not permitted. Finally, if we write a script and we want to terminate it when there is an error we can add the line set -e. For example, a mysecond.sh could be:

#!/bin/bash
# it exits when there is an error

set -e

# it will run the expression 5+5 with an exit code 0
expr 5 + 5
echo $?

# we ask to remove a non-existing file and the exit code is 1
rm non_exist_script.sh
echo $?

# it will not run the expression 5+5 since it will have already exit the script
expr 5 + 5
echo $?

Below you can find a list of exit codes and their corresponding descriptions.

Exit CodeDescription
0Success
1Operation not permitted
2No such file or directory
3No such process
4Interrupted system call
5Input/output error
6No such device or address
7Argument list too long
8Exec format error
9Bad file descriptor
10No child processes
11Resource temporarily unavailable
12Cannot allocate memory
13Permission denied
14Bad address
15Block device required
16Device or resource busy
17File exists
18Invalid cross-device link
19No such device
20Not a directory
21Is a directory
22Invalid argument
23Too many open files in system
24Too many open files
25Inappropriate ioctl for device
26Text file busy
27File too large
28No space left on device
29Illegal seek
30Read-only file system
31Too many links
32Broken pipe
33Numerical argument out of domain
34Numerical result out of range
35Resource deadlock avoided
36File name too long
37No locks available
38Function not implemented
39Directory not empty
40Too many levels of symbolic links
42No message of desired type
43Identifier removed
44Channel number out of range
45Level 2 not synchronized
46Level 3 halted
47Level 3 reset
48Link number out of range
49Protocol driver not attached
50No CSI structure available
51Level 2 halted
52Invalid exchange
53Invalid request descriptor
54Exchange full
55No anode
56Invalid request code
57Invalid slot
59Bad font file format
60Device not a stream
61No data available
62Timer expired
63Out of streams resources
64Machine is not on the network
65Package not installed
66Object is remote
67Link has been severed
68Advertise error
69Srmount error
70Communication error on send
71Protocol error
72Multihop attempted
73RFS specific error
74Bad message
75Value too large for defined data type
76Name not unique on network
77File descriptor in bad state
78Remote address changed
79Can not access a needed shared library
80Accessing a corrupted shared library
81.lib section in a.out corrupted
82Attempting to link in too many shared libraries
83Cannot exec a shared library directly
84Invalid or incomplete multibyte or wide character
85Interrupted system call should be restarted
86Streams pipe error
87Too many users
88Socket operation on non-socket
89Destination address required
90Message too long
91Protocol wrong type for socket
92Protocol not available
93Protocol not supported
94Socket type not supported
95Operation not supported
96Protocol family not supported
97Address family not supported by protocol
98Address already in use
99Cannot assign requested address
100Network is down
101Network is unreachable
102Network dropped connection on reset
103Software caused connection abort
104Connection reset by peer
105No buffer space available
106Transport endpoint is already connected
107Transport endpoint is not connected
108Cannot send after transport endpoint shutdown
109Too many references
110Connection timed out
111Connection refused
112Host is down
113No route to host
114Operation already in progress
115Operation now in progress
116Stale file handle
117Structure needs cleaning
118Not a XENIX named type file
119No XENIX semaphores available
120Is a named type file
121Remote I/O error
122Disk quota exceeded
123No medium found
125Operation canceled
126Required key not available
127Key has expired
128Key has been revoked
129Key was rejected by service
130Owner died
131State not recoverable
132Operation not possible due to RF-kill
133Memory page has hardware error

Share This Post

Share on facebook
Share on linkedin
Share on twitter
Share on email

Subscribe To Our Newsletter

Get updates and learn from the best

More To Explore

Python

Image Captioning with HuggingFace

Image captioning with AI is a fascinating application of artificial intelligence (AI) that involves generating textual descriptions for images automatically.

Python

Intro to Chatbots with HuggingFace

In this tutorial, we will show you how to use the Transformers library from HuggingFace to build chatbot pipelines. Let’s