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 - Linux Tutorial
From the course: LPIC-1 Exam 102 (Version 5.0) Cert Prep
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Introduction to Bash2m 9s
-
(Locked)
What is a shell script?3m 57s
-
(Locked)
Execute compound commands5m 59s
-
(Locked)
Use Command and Variable substitution6m 21s
-
(Locked)
Conditional flow with if, then if3m 12s
-
(Locked)
Conditional flow with case2m 21s
-
(Locked)
Iterate with for loops2m 42s
-
(Locked)
Iterate with while loops1m 30s
-
(Locked)
Using return codes6m 32s
-
(Locked)
Create a monitor script3m
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-