fix for printing ambiguous redirection >& with declare -f

This commit is contained in:
Chet Ramey
2022-06-07 10:31:06 -04:00
parent ebeba87477
commit b95dd4a066
3 changed files with 21 additions and 1 deletions
+11
View File
@@ -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 <lloydsensei@gmail.com>
+1
View File
@@ -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;
+9 -1
View File
@@ -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;