What is the return value of a shell script after successful execution?
A.
1
B.
0
C.
-1
D.
-255
E.
255
The Answer Is:
B
This question includes an explanation.
Explanation:
The return value of a shell script after successful execution is 0. This is a convention followed by most UNIX and Linux commands, programs, and utilities. A return value of 0 indicates that the command or script completed successfully, without any errors. A return value of non-zero (1-255) indicates that the command or script failed, and the value can be interpreted as an error code. The return value of a command or script is stored in the special variable $? and can be used to test the outcome of a command or script123. For example, the following script will print a message based on the return value of the ls command:
#!/bin/bash ls if [ $? -eq 0 ]; then echo “ls command executed successfully” else echo “ls command failed” fi
References: 1: Exit and Exit Status - Linux Documentation Project 2: Linux Passwd Command Help and Examples 3: bash - Which is the best way to check return result? - Unix & Linux Stack Exchange
010-160 PDF/Engine
Printable Format
Value of Money
100% Pass Assurance
Verified Answers
Researched by Industry Experts
Based on Real Exams Scenarios
100% Real Questions
Get 60% Discount on All Products,
Use Coupon: "8w52ceb345"