Bug 9081 - ash return in function exits shell instead of function
Summary: ash return in function exits shell instead of function
Status: RESOLVED INVALID
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.21.x
Hardware: All Linux
: P5 major
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-05 21:52 UTC by Anthony Best
Modified: 2016-07-10 02:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
return exits shell (118 bytes, application/x-shellscript)
2016-07-05 21:52 UTC, Anthony Best
Details

Note You need to log in before you can comment on or make changes to this bug.
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.