Bug 9081

Summary: ash return in function exits shell instead of function
Product: Busybox Reporter: Anthony Best <anthonybest>
Component: OtherAssignee: unassigned
Status: RESOLVED INVALID    
Severity: major CC: busybox-cvs
Priority: P5    
Version: 1.21.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:
Attachments: return exits shell

Description Anthony Best 2016-07-05 21:52:44 UTC
Created attachment 6541 [details]
return exits shell

When return is the first command in the else block inside of a function the shell exits.

It does not exit if return is the second command.

This only seems to happen if the -e flag is set. See attachment for test case.

If you make this change, it starts working again:

       if false ; then
           echo "false"
       else
           echo "anything"
           return
       fi
Comment 1 Denys Vlasenko 2016-07-10 02:03:32 UTC
bash 3.x and 4.x works the same.
"return" with no exitcode uses exitcode of the last command, in this case "false" sets exitcode to 1.
with -e, such return qualifies as failing command, and it makes shell exit.