LX0-104 · Question #459
You are writing a script and want to test the exit status of a process. Which of the following is true?
The correct answer is D. The normal exit value is 0.. In shell scripting, processes typically return an exit status, which is a numerical value indicating the success or failure of the command or script.
Question
Options
- AThe normal exit value differs.
- BYou can't test the normal exit value.
- CThe normal exit value is $EXIT.
- DThe normal exit value is 0.
How the community answered
(42 responses)- A5% (2)
- B2% (1)
- D93% (39)
Why each option
In shell scripting, processes typically return an exit status, which is a numerical value indicating the success or failure of the command or script.
The normal exit value for success is consistently 0 across Unix-like systems, not differing.
The exit value can always be tested in shell scripts using special variables like `$?`.
`$EXIT` is not a standard shell variable for the exit status; the correct variable is `$?`.
By convention, an exit status of 0 signifies successful execution of a command or script, while any non-zero value indicates an error or abnormal termination. This convention allows scripts to test the outcome of operations reliably.
Concept tested: Shell script exit status convention
Source: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Exit-Status
Topics
Community Discussion
No community discussion yet for this question.