Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering Bash

You're reading from   Mastering Bash A Step-by-Step Guide to working with Bash Programming and Shell Scripting

Arrow left icon
Product type Paperback
Published in Jun 2017
Publisher Packt
ISBN-13 9781784396879
Length 502 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Giorgio Zarrelli Giorgio Zarrelli
Author Profile Icon Giorgio Zarrelli
Giorgio Zarrelli
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Let's Start Programming 2. Operators FREE CHAPTER 3. Testing 4. Quoting and Escaping 5. Menus, Arrays, and Functions 6. Iterations 7. Plug into the Real World 8. We Want to Chat 9. Subshells, Signals, and Job Controls 10. Lets Make a Process Chat 11. Living as a Daemon 12. Remote Connections over SSH 13. Its Time for a Timer 14. Time for Safety

Exit codes

We have already seen that when a program encounters issues it exits, usually with an error message. What does exits means? Simply that the code execution terminates and the program, or the script, returns an exit code that informs the system of what happened. This is very handy for us, since we can trap the exit code of a program and decide what to do based on its value.

0

Success

1

Failure

2

Misuse of builtin

126

Command not executable

127

Command not found

128

Invalid argument

128+x

Fatal error exit with signal x

130

Execution terminated by Ctrl +C

255

Exit state out of boundary (0-255)

So, maybe you already guessed, each execution terminates with an exit code, whether successful or not, with an error message or silently:

zarrelli:~$ date ; echo $?
Thu 2 Feb 19:17:48 GMT 2017
0

As you can see, the exit code...

You have been reading a chapter from
Mastering Bash
Published in: Jun 2017
Publisher: Packt
ISBN-13: 9781784396879
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime