From the course: LPIC-1 Exam 102 (Version 5.0) Cert Prep

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Using return codes

Using return codes - Linux Tutorial

From the course: LPIC-1 Exam 102 (Version 5.0) Cert Prep

Start my 1-month free trial

Using return codes

- [Instructor] Every Bash command or function returns a code when run through signal to the OS whether the process was successful or not. If the operation succeeds, it will return a zero return code. If it fails, it will return a nonzero value from one to 255. The reason that zero is success and one through 255 are failures is that our process can fail for many reasons. Using many numbers for failures allows Bash to give more granular output for troubleshooting reasons. The return code is assigned to the question mark variable. We check the value just like we would any variable. Let's see how it works. Let's go to a terminal and type in ls space slash etc slash passwd and hit Enter. Now read the question mark variable echo do an echo space dollar sign question mark and hit Enter. Since our ls command was successful, the return code is zero. Now let's read a file that does not exist. Type in cat space slash etc slash…

Contents