通过 $?
来读取上一个命令执行的退出状态码
#!/bin/bash
# A snipet from a shell script ...
# Next we will invoke a command or another shell script
./myscript.sh
RETURN=$?
if [ $RETURN -eq 0 ];
then
echo "The script myscript.sh was executed successfuly"
exit 0
else
echo "The script myscript.sh was NOT executed successfuly and returned the code $RETURN"
exit $RETURN
fi