]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
commit bash-20070510 snapshot
authorChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:07:47 +0000 (09:07 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 7 Dec 2011 14:07:47 +0000 (09:07 -0500)
16 files changed:
CWRU/CWRU.chlog
MANIFEST
MANIFEST~
doc/bash.1
doc/bash.1~
doc/bashref.texi
doc/bashref.texi~
doc/version.texi
doc/version.texi~
lib/readline/signals.c
print_cmd.c
subst.c
tests/cprint.right
tests/cprint.tests
tests/cprint.tests~ [new file with mode: 0644]
tests/cprint1.sub [new file with mode: 0644]

index 4e7ea3e8fb26c2b4ea890ebe848ed13cf1217a64..3c45f8c4eb159568749fa16d56830fcd1d2bc1a1 100644 (file)
@@ -14570,12 +14570,17 @@ lib/readline/input.c
          (push_index) that caused the 511th character in the buffer to be
          discarded.  Fixes bug reported by Tom Bjorkholm <tom.bjorkholm@ericsson.com>
 
-                                   5/5
+                                   5/8
                                    ---
-print_cmd.c
-       - added logic (inside_pipeline variable) to print_connection code and
-         print_redirection to handle the case of a command with a here
-         document inside a pipeline.  In that case, print_redirection prints
-         the `|' before the here document text, so the parser knows the
-         command is continued.  Fixes problem with exporting functions with
-         pipelines like this reported by Chris Lesner <chris.lesner@gmail.com>
+subst.c
+       - fix parameter_brace_remove_pattern to pass getpattern() newly-allocated
+         memory.  If word expansions (particularly brace expansions) are
+         required, the expansion code will free the string passed to
+         expand_word_internal, and we don't want to free unallocated memory
+         (patstr++) or have duplicate frees (patstr)
+
+                                   5/9
+                                   ---
+lib/readline/signals.c
+       - fix bug in rl_set_signals that caught SIGINT twice and didn't catch
+         SIGTERM.  Bug reported by Ed Kwan <ed.kwan@onstor.com>
index 28a45217020a2e61778222840a2127c42c470d01..a537865d0607f2d8fc17e7bf25608a379f54c0d0 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -725,6 +725,7 @@ tests/cond.right    f
 tests/cond-regexp.sub  f
 tests/cprint.tests     f
 tests/cprint.right     f
+tests/cprint1.sub      f
 tests/dbg-support.right        f
 tests/dbg-support.sub  f
 tests/dbg-support.tests        f
index f368a988c435f74ef74d829213e9fe4118ea2682..28a45217020a2e61778222840a2127c42c470d01 100644 (file)
--- a/MANIFEST~
+++ b/MANIFEST~
@@ -826,6 +826,8 @@ tests/nquote3.tests f
 tests/nquote3.right    f
 tests/nquote4.tests    f
 tests/nquote4.right    f
+tests/nquote5.tests    f
+tests/nquote5.right    f
 tests/posix2.tests     f
 tests/posix2.right     f
 tests/posixpat.tests   f
@@ -903,6 +905,7 @@ tests/run-nquote1   f
 tests/run-nquote2      f
 tests/run-nquote3      f
 tests/run-nquote4      f
+tests/run-nquote5      f
 tests/run-posix2       f
 tests/run-posixpat     f
 tests/run-precedence   f
index 5a3d2ee581195c3ee9d14898ef061f19d3bc6675..91e2df0e156e7243871d0396ad0bebfd2444c2fa 100644 (file)
@@ -688,8 +688,9 @@ An additional binary operator, \fB=~\fP, is available, with the same
 precedence as \fB==\fP and \fB!=\fP.
 When it is used, the string to the right of the operator is considered
 an extended regular expression and matched accordingly (as in \fIregex\fP(3)).  
-The return value is 0 if the string matches
-the pattern, and 1 otherwise.
+Any part of the pattern may be quoted to force it to be matched as a
+string.
+The return value is 0 if the string matches the pattern, and 1 otherwise.
 If the regular expression is syntactically incorrect, the conditional
 expression's return value is 2.
 If the shell option
index 8738a5e929c537f205967b29d7c50964301e4e2d..5a3d2ee581195c3ee9d14898ef061f19d3bc6675 100644 (file)
@@ -2,16 +2,15 @@
 .\" MAN PAGE COMMENTS to
 .\"
 .\"    Chet Ramey
-.\"    Information Network Services
 .\"    Case Western Reserve University
 .\"    chet@po.cwru.edu
 .\"
-.\"    Last Change: Fri Jan 12 16:29:22 EST 2007
+.\"    Last Change: Tue May  1 10:05:17 EDT 2007
 .\"
 .\" bash_builtins, strip all but Built-Ins section
 .if \n(zZ=1 .ig zZ
 .if \n(zY=1 .ig zY
-.TH BASH 1 "2007 January 12" "GNU Bash-3.2"
+.TH BASH 1 "2007 May 1" "GNU Bash-3.2"
 .\"
 .\" There's some problem with having a `@'
 .\" in a tagged paragraph with the BSD man macros.
@@ -51,8 +50,8 @@ bash \- GNU Bourne-Again SHell
 [options]
 [file]
 .SH COPYRIGHT
-.if n Bash is Copyright (C) 1989-2005 by the Free Software Foundation, Inc.
-.if t Bash is Copyright \(co 1989-2005 by the Free Software Foundation, Inc.
+.if n Bash is Copyright (C) 1989-2007 by the Free Software Foundation, Inc.
+.if t Bash is Copyright \(co 1989-2007 by the Free Software Foundation, Inc.
 .SH DESCRIPTION
 .B Bash
 is an \fBsh\fR-compatible command language interpreter that
@@ -646,7 +645,8 @@ The return status is the exit status of
 Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and
 \fB}\fP are \fIreserved words\fP and must occur where a reserved
 word is permitted to be recognized.  Since they do not cause a word
-break, they must be separated from \fIlist\fP by whitespace.
+break, they must be separated from \fIlist\fP by whitespace or another
+shell metacharacter.
 .TP
 ((\fIexpression\fP))
 The \fIexpression\fP is evaluated according to the rules described
@@ -2570,7 +2570,7 @@ The \fIpattern\fP is expanded to produce a pattern just as in
 pathname expansion.
 \fIParameter\fP is expanded and the longest match of \fIpattern\fP
 against its value is replaced with \fIstring\fP.
-If \Ipattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are
+If \fIpattern\fP begins with \fB/\fP, all matches of \fIpattern\fP are
 replaced with \fIstring\fP.  Normally only the first match is replaced.
 If \fIpattern\fP begins with \fB#\fP, it must match at the beginning
 of the expanded value of \fIparameter\fP.
@@ -8319,6 +8319,7 @@ an argument of \fB\-\-\fP as signifying the end of options.
 .if n .sp 1
 Expressions may be combined using the following operators, listed
 in decreasing order of precedence.
+The evaluation depends on the number of arguments; see below.
 .RS
 .PD 0
 .TP
@@ -8376,14 +8377,14 @@ under
 .BR "CONDITIONAL EXPRESSIONS" ,
 the result of the expression is the result of the binary test using
 the first and third arguments as operands.
+The \fB\-a\fP and \fB\-o\fP operators are considered binary operators
+when there are three arguments.  
 If the first argument is \fB!\fP, the value is the negation of
 the two-argument test using the second and third arguments.
 If the first argument is exactly \fB(\fP and the third argument is
 exactly \fB)\fP, the result is the one-argument test of the second
 argument.
 Otherwise, the expression is false.
-The \fB\-a\fP and \fB\-o\fP operators are considered binary operators
-in this case.  
 .TP
 4 arguments
 If the first argument is \fB!\fP, the result is the negation of
index 62b0c5978db795752ccc34f8c97cdc8ba2c146d9..227d6fe38804f10c65a82ef7b79de49f77309447 100644 (file)
@@ -959,13 +959,13 @@ is enabled, the match is performed without regard to the case
 of alphabetic characters.
 The return value is 0 if the string matches (@samp{==}) or does not
 match (@samp{!=})the pattern, and 1 otherwise.
-Any part of the pattern may be quoted to force it to be matched as a
-string.
+Any part of the pattern may be quoted to force it to be matched as a string.
 
 An additional binary operator, @samp{=~}, is available, with the same
 precedence as @samp{==} and @samp{!=}.
 When it is used, the string to the right of the operator is considered
 an extended regular expression and matched accordingly (as in @i{regex}3)).  
+Any part of the pattern may be quoted to force it to be matched as a string.
 The return value is 0 if the string matches
 the pattern, and 1 otherwise.
 If the regular expression is syntactically incorrect, the conditional
index 374ace287459e58daec3765806acad5eb767206d..62b0c5978db795752ccc34f8c97cdc8ba2c146d9 100644 (file)
@@ -1041,7 +1041,8 @@ The semicolon (or newline) following @var{list} is required.
 In addition to the creation of a subshell, there is a subtle difference
 between these two constructs due to historical reasons.  The braces
 are @code{reserved words}, so they must be separated from the @var{list}
-by @code{blank}s.  The parentheses are @code{operators}, and are
+by @code{blank}s or other shell metacharacters.
+The parentheses are @code{operators}, and are
 recognized as separate tokens by the shell even if they are not separated
 from the @var{list} by whitespace.
 
@@ -1092,7 +1093,8 @@ Note that for historical reasons, in the most common usage the curly braces
 that surround the body of the function must be separated from the body by
 @code{blank}s or newlines.
 This is because the braces are reserved words and are only recognized
-as such when they are separated by whitespace.
+as such when they are separated from the command list
+by whitespace or another shell metacharacter.
 Also, when using the braces, the @var{list} must be terminated by a semicolon,
 a @samp{&}, or a newline.
 
@@ -2918,6 +2920,7 @@ be a @code{]}.
 
 Expressions may be combined using the following operators, listed in
 decreasing order of precedence.
+The evaluation depends on the number of arguments; see below.
 
 @table @code
 @item ! @var{expr}
@@ -2958,14 +2961,14 @@ If the second argument is one of the binary conditional
 operators (@pxref{Bash Conditional Expressions}), the
 result of the expression is the result of the binary test using the
 first and third arguments as operands.
+The @samp{-a} and @samp{-o} operators are considered binary operators
+when there are three arguments.
 If the first argument is @samp{!}, the value is the negation of
 the two-argument test using the second and third arguments.
 If the first argument is exactly @samp{(} and the third argument is
 exactly @samp{)}, the result is the one-argument test of the second
 argument.
 Otherwise, the expression is false.
-The @samp{-a} and @samp{-o} operators are considered binary operators
-in this case.  
 
 @item 4 arguments
 If the first argument is @samp{!}, the result is the negation of
@@ -4638,6 +4641,8 @@ for @var{strftime} to print the time stamp associated with each history
 entry displayed by the @code{history} builtin.
 If this variable is set, time stamps are written to the history file so
 they may be preserved across shell sessions.
+This uses the history comment character to distinguish timestamps from
+other history lines.
 
 @item HOSTFILE
 Contains the name of a file in the same format as @file{/etc/hosts} that
index dc36632b552ccef94c145cfacdaf2e9869d116ed..c6ed0f0de55510edcfc47aafb63157adce4f2776 100644 (file)
@@ -2,9 +2,9 @@
 Copyright (C) 1988-2007 Free Software Foundation, Inc.
 @end ignore
 
-@set LASTCHANGE Tue May  1 10:05:36 EDT 2007
+@set LASTCHANGE Mon May 14 10:02:55 EDT 2007
 
 @set EDITION 3.2
 @set VERSION 3.2
-@set UPDATED 1 May 2007
+@set UPDATED 14 May 2007
 @set UPDATED-MONTH May 2007
index 42375e301dacdb50260b661baa9332d62d26c02f..dc36632b552ccef94c145cfacdaf2e9869d116ed 100644 (file)
@@ -1,10 +1,10 @@
 @ignore
-Copyright (C) 1988-2006 Free Software Foundation, Inc.
+Copyright (C) 1988-2007 Free Software Foundation, Inc.
 @end ignore
 
-@set LASTCHANGE Sat Dec 30 19:31:54 EST 2006
+@set LASTCHANGE Tue May  1 10:05:36 EDT 2007
 
 @set EDITION 3.2
 @set VERSION 3.2
-@set UPDATED 30 December 2006
-@set UPDATED-MONTH December 2006
+@set UPDATED 1 May 2007
+@set UPDATED-MONTH May 2007
index 54f2a642846d388f7c05b14ef60779180230bb46..c088b6f42c99feafc4e670e411365f2f2be350e3 100644 (file)
@@ -300,7 +300,7 @@ rl_set_signals ()
       sigemptyset (&bset);
 
       sigaddset (&bset, SIGINT);
-      sigaddset (&bset, SIGINT);
+      sigaddset (&bset, SIGTERM);
 #if defined (SIGQUIT)
       sigaddset (&bset, SIGQUIT);
 #endif
index 28bec1b5e6f400afd443cc48f8d0c59d1e4b88b5..d1dfd1a78be7ed92def9cbac50c01de36c1d9cf1 100644 (file)
@@ -106,15 +106,7 @@ int command_string_index = 0;
 
 /* Non-zero means the stuff being printed is inside of a function def. */
 static int inside_function_def;
-
-/* Used to decide where to put the `|' if the command in the pipeline has
-   here documents associated with it.  If non-zero, print_redirection
-   prints the `|' before the text of the here document and print_connection
-   suppresses the `|'. */
-static int inside_pipeline;
 static int skip_this_indent;
-
-/* Flag indicating we printed a here-document. */
 static int was_heredoc;
 
 /* The depth of the group commands that we are currently printing.  This
@@ -141,7 +133,7 @@ char *
 make_command_string (command)
      COMMAND *command;
 {
-  command_string_index = was_heredoc = inside_pipeline = 0;
+  command_string_index = was_heredoc = 0;
   make_command_string_internal (command);
   return (the_printed_command);
 }
@@ -223,11 +215,7 @@ make_command_string_internal (command)
        case cm_connection:
 
          skip_this_indent++;
-         if (command->value.Connection->connector == '|')
-           inside_pipeline = 1;
          make_command_string_internal (command->value.Connection->first);
-         if (command->value.Connection->connector == '|')
-           inside_pipeline = 0;
 
          switch (command->value.Connection->connector)
            {
@@ -235,10 +223,7 @@ make_command_string_internal (command)
            case '|':
              {
                char c = command->value.Connection->connector;
-               if (c == '&' || was_heredoc == 0)
-                 cprintf (" %c", c);
-               else
-                 was_heredoc = 0;
+               cprintf (" %c", c);
                if (c != '&' || command->value.Connection->second)
                  {
                    cprintf (" ");
@@ -866,10 +851,6 @@ print_redirection_list (redirects)
      print the here documents. */
   if (heredocs)
     {
-if (inside_pipeline)
-{
-itrace("print_redirection_list: here documents inside pipeline");
-}
       cprintf (" "); 
       for (hdtail = heredocs; hdtail; hdtail = hdtail->next)
        {
@@ -887,7 +868,6 @@ print_redirection (redirect)
 {
   int kill_leading, redirector, redir_fd;
   WORD_DESC *redirectee;
-  char *x;
 
   kill_leading = 0;
   redirectee = redirect->redirectee.filename;
@@ -925,16 +905,17 @@ print_redirection (redirect)
       if (redirector != 0)
        cprintf ("%d", redirector);
       /* If the here document delimiter is quoted, single-quote it. */
-      x = (redirect->redirectee.filename->flags & W_QUOTED)
-               ? sh_single_quote (redirect->here_doc_eof)
-               : redirect->here_doc_eof;
-      cprintf ("<<%s%s", kill_leading? "-" : "", x);
-      if (x != redirect->here_doc_eof)
-       free (x);
-if (inside_pipeline)
-  cprintf (" |");
-      cprintf ("\n");
-      cprintf ("%s%s", redirect->redirectee.filename->word, redirect->here_doc_eof);
+      if (redirect->redirectee.filename->flags & W_QUOTED)
+       {
+         char *x;
+         x = sh_single_quote (redirect->here_doc_eof);
+         cprintf ("<<%s%s\n", kill_leading? "-" : "", x);
+         free (x);
+       }
+      else
+       cprintf ("<<%s%s\n", kill_leading? "-" : "", redirect->here_doc_eof);
+      cprintf ("%s%s",
+              redirect->redirectee.filename->word, redirect->here_doc_eof);
       break;
 
     case r_reading_string:
@@ -1010,7 +991,6 @@ reset_locals ()
 {
   inside_function_def = 0;
   indentation = 0;
-  inside_pipeline = 0;
 }
 
 static void
@@ -1030,7 +1010,7 @@ print_function_def (func)
   inside_function_def++;
   indentation += indentation_amount;
 
-  cmdcopy = copy_command (func->command);      /* possible mem leak on unwind-protect */
+  cmdcopy = copy_command (func->command);
   if (cmdcopy->type == cm_group)
     {
       func_redirects = cmdcopy->redirects;
@@ -1075,7 +1055,6 @@ named_function_string (name, command, multi_line)
   old_indent = indentation;
   old_amount = indentation_amount;
   command_string_index = was_heredoc = 0;
-  inside_pipeline = 0;
 
   if (name && *name)
     cprintf ("%s ", name);
diff --git a/subst.c b/subst.c
index 74ae998d25ee6c87e387853beb591ce5b079a17c..6abc16608288a71d02bbc7d4c83be2f7cf00b786 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -4006,7 +4006,11 @@ parameter_brace_remove_pattern (varname, value, patstr, rtype, quoted)
   if (patspec == RP_LONG_LEFT || patspec == RP_LONG_RIGHT)
     patstr++;
 
-  pattern = getpattern (patstr, quoted, 1);
+  /* Need to pass getpattern newly-allocated memory in case of expansion --
+     the expansion code will free the passed string on an error. */
+  temp1 = savestring (patstr);
+  pattern = getpattern (temp1, quoted, 1);
+  free (temp1);
 
   temp1 = (char *)NULL;                /* shut up gcc */
   switch (vtype)
@@ -5974,7 +5978,7 @@ parameter_brace_expand (string, indexp, quoted, quoted_dollar_atp, contains_doll
   int t_index, sindex, c, tflag;
   intmax_t number;
 
-  value = (char *)NULL;
+  temp = temp1 = value = (char *)NULL;
   var_is_set = var_is_null = var_is_special = check_nullness = 0;
   want_substring = want_indir = want_patsub = 0;
 
@@ -6059,7 +6063,6 @@ parameter_brace_expand (string, indexp, quoted, quoted_dollar_atp, contains_doll
       temp = (char *)NULL;
       goto bad_substitution;
     }
-
   /* Indirect expansion begins with a `!'.  A valid indirect expansion is
      either a variable name, one of the positional parameters or a special
      variable that expands to one of the positional parameters. */
index 200007241e87eea12c1f7e47f32156191510ed74..3a9f3644bf10e5478dc0457b09c7f638131c7a9b 100644 (file)
@@ -70,3 +70,50 @@ fu%nc ()
 { 
     echo abcde
 }
+a is a function
+a () 
+{ 
+    cat  <<-'+'
+               cat - | utkSort
+               itkSchemaToColumnType
+               atkCacheToColumnType \"$npName\" | atkActiveTableLineSelect
+| utkSort
+               atkCacheToColumnType \"$npName\" |
+atkTransactionTableLineSelect | utkSort
+               itkDirToColumnType \"$dirName\" | atkActiveTableLineSelect |
+utkSort
+               itkDirToColumnType \"$dirName\" | atkActiveTableLineSelect |
+utkSort
++
+ | tr "\t" " " | tr -s " "
+}
+b is a function
+b () 
+{ 
+    cat /etc/passwd | cat -  <<-'+'
+more
+passwords
+from
+the
+file
++
+ | tr -s " "
+}
+c is a function
+c () 
+{ 
+    cat /etc/passwd | tr -s " " | cat -  <<-'+'
+more
+passwords
+from
+the
+file
++
+ | cat -  <<-'foo'
+last
+bunch
+of
+words
+foo
+
+}
index 08ff1ebc0f7183ee4aa50cbe516a0deea9c40f95..fa2a75cab7d2be37a240a555415efce6d2b3c5df 100644 (file)
@@ -65,3 +65,5 @@ type tf
 type tf2
 
 tf
+
+${THIS_SH} ./cprint1.sub
diff --git a/tests/cprint.tests~ b/tests/cprint.tests~
new file mode 100644 (file)
index 0000000..08ff1eb
--- /dev/null
@@ -0,0 +1,67 @@
+#
+# a nonsense script and shell function to test out the command printing code
+#
+tf()
+{
+       # simple command with redir
+       echo this is ${0##*/} > /dev/null
+
+       # pipeline
+       echo a | cat - > /dev/null
+
+       test -f ${0##*/} && echo ${0##*/} is a regular file
+       test -d ${0##*/} || echo ${0##*/} is not a directory
+
+       echo a ; echo b ; echo c
+
+       echo background >/dev/null &
+
+       ( exit 1 )
+       echo $?
+
+       { echo a ; }
+
+       i=0
+       while (( i < 3 )); do
+               test -r /dev/fd/$i
+               i=$(( i + 1 ))
+       done
+
+       [[ -r /dev/fd/0 && -w /dev/fd/1 ]] || echo oops > /dev/null
+
+       for name in $( echo 1 2 3 ); do
+               test -r /dev/fd/$name
+       done
+
+       if [[ -r /dev/fd/0 && -w /dev/fd/1 ]] ; then
+               echo ok > /dev/null
+       elif (( 7 > 40 )) ; then
+               echo oops
+       else
+               echo done
+       fi > /dev/null
+
+       case $PATH in
+       *$PWD*) echo \$PWD in \$PATH ;;
+       *)      echo \$PWD not in \$PATH ;;
+       esac > /dev/null
+
+       while false; do echo z; done > /dev/null
+
+       until true; do echo z ; done > /dev/null
+
+       echo \&\|'()' \{ echo abcde \; \}
+       # when not in POSIX mode, we can have weirdly-named functions
+       eval fu\%nc'()' \{ echo abcde \; \}
+       type fu\%nc
+}
+
+tf2()
+{
+       ( { time -p echo a | cat - > /dev/null ; } ) 2>&1
+}
+
+type tf
+type tf2
+
+tf
diff --git a/tests/cprint1.sub b/tests/cprint1.sub
new file mode 100644 (file)
index 0000000..4273045
--- /dev/null
@@ -0,0 +1,48 @@
+a()
+{
+       cat <<-'+' | tr "\t" " " | tr -s " "
+               cat - | utkSort
+               itkSchemaToColumnType
+               atkCacheToColumnType \"$npName\" | atkActiveTableLineSelect
+| utkSort
+               atkCacheToColumnType \"$npName\" |
+atkTransactionTableLineSelect | utkSort
+               itkDirToColumnType \"$dirName\" | atkActiveTableLineSelect |
+utkSort
+               itkDirToColumnType \"$dirName\" | atkActiveTableLineSelect |
+utkSort
+       +
+}
+
+type a
+
+b()
+{
+       cat /etc/passwd | cat - <<-'+' | tr -s " "
+       more
+       passwords
+       from
+       the
+       file
+       +
+}
+
+type b
+
+c()
+{
+       cat /etc/passwd | tr -s " " | cat - <<-'+' | cat - <<-'foo'
+       more
+       passwords
+       from
+       the
+       file
+       +
+last
+bunch
+of
+words
+foo
+}
+
+type c