Before this patch, if allexport was set, $_ gained the "x" attribute after PROMPT_COMMAND finished running, that would only get removed after the next simple command is executed.
$ PROMPT_COMMAND=: $ : foo $ declare -p _ declare -- _="foo" $ set -a $ : bar $ declare -p _ declare -x _="bar" $ : zoo; declare -p _; : bee declare -- _="zoo" $ declare -p _ declare -x _="bee" --- execute_cmd.c | 3 +-- execute_cmd.h | 2 ++ parse.y | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/execute_cmd.c b/execute_cmd.c index d4c082d0..18540409 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -121,7 +121,6 @@ extern int close (int); /* Static functions defined and used in this file. */ static void close_pipes (int, int); static void do_piping (int, int); -static void bind_lastarg (char *); static int shell_control_structure (enum command_type); static void cleanup_redirects (REDIRECT *); @@ -4000,7 +3999,7 @@ execute_cond_command (COND_COM *cond_command) } #endif /* COND_COMMAND */ -static void +void bind_lastarg (char *arg) { SHELL_VAR *var; diff --git a/execute_cmd.h b/execute_cmd.h index 37e386ab..944b6a98 100644 --- a/execute_cmd.h +++ b/execute_cmd.h @@ -85,6 +85,8 @@ extern void dispose_exec_redirects (void); extern int execute_shell_function (SHELL_VAR *, WORD_LIST *); +extern void bind_lastarg (char *); + extern struct coproc *getcoprocbypid (pid_t); extern struct coproc *getcoprocbyname (const char *); diff --git a/parse.y b/parse.y index f5199f15..8db9bee6 100644 --- a/parse.y +++ b/parse.y @@ -2848,7 +2848,7 @@ execute_variable_command (const char *command, const char *vname) parse_and_execute (savestring (command), vname, SEVAL_NONINT|SEVAL_NOHIST|SEVAL_NOOPTIMIZE); restore_parser_state (&ps); - bind_variable ("_", last_lastarg, 0); + bind_lastarg (last_lastarg); FREE (last_lastarg); if (token_to_read == '\n') /* reset_parser was called */ -- 2.39.1