From a2c579050fbf40eb9192f043e901e6b2eff3ab50 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 15 Apr 2015 09:44:19 +0100 Subject: 34887: Fix POSIX_BUILTINS with assignment. In the form var=val command special-builtin-or-func the var is restored after execution, unlike the case where "command" is absent. Clear up case in code that handles this. Add tests. --- Src/exec.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'Src/exec.c') diff --git a/Src/exec.c b/Src/exec.c index 1a6149ad7..2ee37d09f 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3384,14 +3384,28 @@ execcmd(Estate state, int input, int output, int how, int last1) LinkList restorelist = 0, removelist = 0; /* builtin or shell function */ - if (!forked && ((cflags & BINF_COMMAND) || - (unset(POSIXBUILTINS) && !assign) || - (isset(POSIXBUILTINS) && !is_shfunc && - !(hn->flags & BINF_PSPECIAL)))) { - if (varspc) + if (!forked && varspc) { + int do_save = 0; + if (isset(POSIXBUILTINS)) { + /* + * If it's a function or special builtin --- save + * if it's got "command" in front. + * If it's a normal command --- save. + */ + if (is_shfunc || (hn->flags & BINF_PSPECIAL)) + do_save = (orig_cflags & BINF_COMMAND); + else + do_save = 1; + } else { + /* + * Save if it's got "command" in front or it's + * not a magic-equals assignment. + */ + if ((cflags & BINF_COMMAND) || !assign) + do_save = 1; + } + if (do_save) save_params(state, varspc, &restorelist, &removelist); - else - restorelist = removelist = NULL; } if (varspc) { /* Export this if the command is a shell function, -- cgit v1.2.3-70-g09d2