I was interested is there any difference between two commands in bash: exit and return. This article helped me. Also I've made a little experiment with script exit codes.
Let's execute a script test.sh:
The output will be:
$ echo $?
So, the $? returns the last response for both cases. The only difference is that return we only could use for functions.
If we'll try to execute script
we will fahe an error:
-bash: return: can only `return' from a function or sourced script
But exit command will work for function and...