diff options
author | jilles <jilles@FreeBSD.org> | 2013-09-04 22:10:16 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2013-09-04 22:10:16 +0000 |
commit | ad7328341af15585f1dee4fbb63f288d2b2917e2 (patch) | |
tree | 00235be2a41fac24160537f8172d9ce83957898a /bin/sh/eval.c | |
parent | 206a10e8a633f64ba34396341d375e620bba21d2 (diff) | |
download | FreeBSD-src-ad7328341af15585f1dee4fbb63f288d2b2917e2.zip FreeBSD-src-ad7328341af15585f1dee4fbb63f288d2b2917e2.tar.gz |
sh: Make return return from the closest function or dot script.
Formerly, return always returned from a function if it was called from a
function, even if there was a closer dot script. This was for compatibility
with the Bourne shell which only allowed returning from functions.
Other modern shells and POSIX return from the function or the dot script,
whichever is closest.
Git 1.8.4's rebase --continue depends on the POSIX behaviour.
Reported by: Christoph Mallon, avg
Diffstat (limited to 'bin/sh/eval.c')
-rw-r--r-- | bin/sh/eval.c | 14 |
1 files changed, 4 insertions, 10 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c index 655bf81..b8f76d5 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -324,7 +324,7 @@ skipping: if (evalskip == SKIPCONT && --skipcount <= 0) { } if (evalskip == SKIPBREAK && --skipcount <= 0) evalskip = 0; - if (evalskip == SKIPFUNC || evalskip == SKIPFILE) + if (evalskip == SKIPRETURN) status = exitstatus; break; } @@ -1068,7 +1068,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) funcnest--; popredir(); INTON; - if (evalskip == SKIPFUNC) { + if (evalskip == SKIPRETURN) { evalskip = 0; skipcount = 0; } @@ -1305,14 +1305,8 @@ returncmd(int argc, char **argv) { int ret = argc > 1 ? number(argv[1]) : oexitstatus; - if (funcnest) { - evalskip = SKIPFUNC; - skipcount = 1; - } else { - /* skip the rest of the file */ - evalskip = SKIPFILE; - skipcount = 1; - } + evalskip = SKIPRETURN; + skipcount = 1; return ret; } |