LFCS · 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, a process conventionally returns an exit status of 0 to indicate successful execution.
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
(67 responses)- A4% (3)
- B1% (1)
- C1% (1)
- D93% (62)
Why each option
In shell scripting, a process conventionally returns an exit status of `0` to indicate successful execution.
The normal exit value is consistently `0` for success; it does not differ based on the process type.
The exit value is always testable in shell scripts using the special variable `$?` immediately after a command execution.
`$EXIT` is not a standard or recognized shell variable for storing the exit status of the last executed command; the correct variable is `$?`.
In Unix-like operating systems and shell scripting, a process conventionally returns an exit status of `0` to indicate successful execution and completion without errors. Any non-zero exit status (typically 1-255) indicates some form of error or abnormal termination.
Concept tested: Shell script exit status conventions
Source: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Exit-Status
Topics
Community Discussion
No community discussion yet for this question.