Put an Exit Code function in Scripts

To check the exit code of a process, test against the variable $?
Put an Exit Code function in Scripts:

rsync -avu /Folder1/ /Folder2/
if [ $? = 0 ]; then
     echo "The sync finished without an error!"
else 
     echo "The rsync had problems!!"
fi

Alternatively, do the same thing on one line:
rsync -avu /Folder1/ /Folder2/ && ( echo “Rsync Finished” | echo “Rsync had problems” )

This is a great resource and where this was taken from
Link:

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
Share via
Copy link