The the simpler form of a function is:
name () { commands return }
I find no difference in a function with and without return.
Suppose the minimal code:
step_forward (){
echo "step one;"
return
}
turn_around() {
echo "turn around."
return
}
step_forward
turn_around
Run and check the exit status:
$ bash testing.sh
step one;
turn around.
$ echo $?
0
Run it again after commenting out return
$ bash testing.sh
step one;
turn around.
$ echo $?
0
In what circumstances should a function end with a return?
A
return
value is not required in a function. Normally areturn
would be used in a script for an exit value to be returned. Exit values are normally like a1
or a0
where a lot of scripters might use it for a0
as successful and a1
as not successful.Examples:
And this answer I wrote a little bit ago does not have return values but still gives output https://askubuntu.com/a/1023493/231142
Example:
Hope this helps!