Menu

Post image 1
Post image 2
1 / 2
0

Stop Googling "what is exit code 127" There's a better way to handle it

DEV Community·Anguishe·26 days ago
#kdKHt9gu
#bash#linux#webdev#code#exit#case
Reading 0:00
15s threshold

Exit code 127 means "command not found." I know that now. But the first dozen times I saw it, I Googled it. Every time. Because exit codes are one of those things that are fundamental to bash scripting but never feel intuitive until you've been burned by them enough. Here's a quick table of the ones that show up constantly: Code Meaning 0 Success 1 General error 2 Misuse of shell built-in 126 Command found but not executable 127 Command not found 130 Script killed with Ctrl-C 137 Process killed with SIGKILL (kill -9) 139 Segmentation fault 143 Process killed with SIGTERM The rule for codes above 128: subtract 128 to get the signal number. 137 = 128 + 9 (SIGKILL). 143 = 128 + 15 (SIGTERM). Once you know that pattern, a lot of the high-numbered codes make sense. But looking up the code is only half the problem The other half is writing the error handler. And this is where most scripts fall short. They check $? after a command, but the handler is usually something like: if [ $?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More