]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fix for printing ambiguous redirection >& with declare -f
authorChet Ramey <chet.ramey@case.edu>
Tue, 7 Jun 2022 14:31:06 +0000 (10:31 -0400)
committerChet Ramey <chet.ramey@case.edu>
Tue, 7 Jun 2022 14:31:06 +0000 (10:31 -0400)
CWRU/CWRU.chlog
lib/sh/shmatch.c
print_cmd.c

index a813fcb9463da83dc9754c62cb6903e2a2867418..c417cfa305c70833555def359739d0062bbbed55 100644 (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>
index 26b4bba93c39c99b9011f74fbbed51f7e85b9a06..a717d45c9fd71aa33a3b0cbe0661336f95e3e33e 100644 (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;
index 9f3f670c8fa0cc9b0329e9127abea68454f6229d..188695bea48067b14362fe48198a92f9b4421bb2 100644 (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;