From b95dd4a06690e5ad365eb40371b94df4538b5fbd Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Tue, 7 Jun 2022 10:31:06 -0400 Subject: [PATCH] fix for printing ambiguous redirection >& with declare -f --- CWRU/CWRU.chlog | 11 +++++++++++ lib/sh/shmatch.c | 1 + print_cmd.c | 10 +++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index a813fcb9..c417cfa3 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -3670,3 +3670,14 @@ lib/sh/shmatch.c doc/{bash.1,bashref.texi} - BASH_REMATCH: add caveat about making it a local variable + + 6/6 + --- +print_cmd.c + - print_redirection: if the redirectee for r_duplicating_output_word + (r_duplicating_input_word) is 1 (0), don't print it; only print a + non-default file descriptor number + - print_redirection_list: remove the code that tries to temporarily + translate a >&word redirection to >&word now that we won't print a + non-default file descriptor number. Fixes issue with `declare -f' and + function export reported by Namikaze Minato diff --git a/lib/sh/shmatch.c b/lib/sh/shmatch.c index 26b4bba9..a717d45c 100644 --- a/lib/sh/shmatch.c +++ b/lib/sh/shmatch.c @@ -100,6 +100,7 @@ sh_regmatch (string, pattern, flags) unbind_global_variable_noref ("BASH_REMATCH"); rematch = make_new_array_variable ("BASH_REMATCH"); #else + /* TAG:bash-5.3 */ rematch = builtin_find_indexed_array ("BASH_REMATCH", 1); #endif amatch = rematch ? array_cell (rematch) : (ARRAY *)0; diff --git a/print_cmd.c b/print_cmd.c index 9f3f670c..188695be 100644 --- a/print_cmd.c +++ b/print_cmd.c @@ -1,6 +1,6 @@ /* print_command -- A way to make readable commands from a command tree. */ -/* Copyright (C) 1989-2021 Free Software Foundation, Inc. +/* Copyright (C) 1989-2022 Free Software Foundation, Inc. This file is part of GNU Bash, the Bourne Again SHell. @@ -1055,6 +1055,9 @@ print_redirection_list (redirects) else hdtail = heredocs = newredir; } +#if 0 + /* Remove this heuristic now that the command printing code doesn't + unconditionally put in the redirector file descriptor. */ else if (redirects->instruction == r_duplicating_output_word && (redirects->flags & REDIR_VARASSIGN) == 0 && redirects->redirector.dest == 1) { /* Temporarily translate it as the execution code does. */ @@ -1064,6 +1067,7 @@ print_redirection_list (redirects) print_redirection (redirects); redirects->instruction = r_duplicating_output_word; } +#endif else print_redirection (redirects); @@ -1222,6 +1226,8 @@ print_redirection (redirect) case r_duplicating_input_word: if (redirect->rflags & REDIR_VARASSIGN) cprintf ("{%s}<&%s", redir_word->word, redirectee->word); + else if (redirector == 0) + cprintf ("<&%s", redirectee->word); else cprintf ("%d<&%s", redirector, redirectee->word); break; @@ -1229,6 +1235,8 @@ print_redirection (redirect) case r_duplicating_output_word: if (redirect->rflags & REDIR_VARASSIGN) cprintf ("{%s}>&%s", redir_word->word, redirectee->word); + else if (redirector == 1) + cprintf (">&%s", redirectee->word); else cprintf ("%d>&%s", redirector, redirectee->word); break;