What does the command 'echo $?' display?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

What does the command 'echo $?' display?

Explanation:
The thing being tested is how the shell reports the completion status of the command that just ran. The special parameter $? holds that exit status. When you run a command, it returns an exit code: 0 means success, and any nonzero value indicates an error or some condition. Echoing $? prints that numeric code, letting you quickly see whether the previous command succeeded. For example, running a successful command like true and then echoing $? will show 0. Running a failing command like false and then echoing $? will show 1. If a command fails in a way that returns a different nonzero code, that exact number will appear. Remember, $? reflects only the most recently executed foreground command, and it gets overwritten by the next command’s exit status.

The thing being tested is how the shell reports the completion status of the command that just ran. The special parameter $? holds that exit status. When you run a command, it returns an exit code: 0 means success, and any nonzero value indicates an error or some condition. Echoing $? prints that numeric code, letting you quickly see whether the previous command succeeded.

For example, running a successful command like true and then echoing $? will show 0. Running a failing command like false and then echoing $? will show 1. If a command fails in a way that returns a different nonzero code, that exact number will appear. Remember, $? reflects only the most recently executed foreground command, and it gets overwritten by the next command’s exit status.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy