After a script or a command ended, it's useful to leave a trace in the system of its execution, in order to allow the following scripts to know if it was successful and to behave consequently. For this purpose this command exists:
It ends the execution of a script and makes return_value
available in the operating system environment.
The following script shows an interesting usage of the return values and command line parameters:
# The following script searches for the user "pippo" in the system
# user list through the grep command. According to the return
# value of grep, it visualizes a message telling if the user
# was found or not.
# It searches for the user "pippo" in the list of system users
grep "admin" /etc/passwd
# According to the return value, it prints a message.
# Remember that $? returns the return value of the last
# executed command.
if [ "$?" -eq 0 ];
echo "User found"
echo "User not found"