Exit Codes

Video Activity
Join over 3 million cybersecurity professionals advancing their career
Sign up with
Required fields are marked with an *
or

Already have an account? Sign In »

Time
21 hours 25 minutes
Difficulty
Intermediate
CEU/CPE
21
Video Transcription
00:00
>> Hey, there Cybrarians.
00:00
Welcome back to the Linux plus course here at Cybrary,
00:00
I'm your instructor Rob [inaudible] ,
00:00
and in today's lesson, we're going to
00:00
be discussing exit codes.
00:00
Upon completion of this lesson,
00:00
you're going to be able to understand
00:00
the importance of exit codes,
00:00
as well as use the exit command to
00:00
change the value of exit codes.
00:00
When any command ends,
00:00
it's going to return an exit status either
00:00
to the shell or to the script where it was executed,
00:00
and this status is used to determine if
00:00
the command is completed successfully or not.
00:00
Now the exit status value
00:00
gets stored in a special variable.
00:00
That variable is the
00:00
>> dollar sign question mark variable,
00:00
>> and we can see the contents of this variable
00:00
>> just like we did with any other variables when we
00:00
>> were doing variable expansion,
00:00
we can do echo dollar sign?
00:00
Now, when we're echoing the contents of that variable,
00:00
if the value of the variable is the number zero,
00:00
it means that that previous command was successful.
00:00
But if dollar sign?
00:00
returns any number one or greater,
00:00
that means the previous command
00:00
has failed and we've got an issue.
00:00
The exit status can be changed inside of a script
00:00
by using the exit command as well.
00:00
This is generally done when you want to provide
00:00
a numerical identifier for different results.
00:00
Then once you have those
00:00
>> different results in your code,
00:00
>> you can perform another action upon them.
00:00
This goes into condition statements like if
00:00
this value was found after we ran this,
00:00
do something else, and we're going to cover
00:00
condition statements in a little bit.
00:00
For now, just know that you can tell
00:00
a command to exit and then provide a code.
00:00
for example, we can say exit 42,
00:00
and if we do echo dollar sign question mark.
00:00
it will return the value 42.
00:00
In this lesson, we covered
00:00
the importance of exit codes as well as
00:00
using exit commands to change exit codes.
00:00
Thanks so much for being here and I look
00:00
forward to seeing you in the next lesson.
Up Next