Interview Questions

How will you get the exit status of the previous command execution in Shell?

Execute a command like "ls -ltr" and perform the following.

echo $?
[or]
exit_status=$?
echo $exit_status
<code>

This will print the exit status of the previous command execution. If the value is 0, then then program completed without any errors. If the value is a non-zero element, then there is an error in execution.