]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
a select command invalid selection variable name is now a fatal error in posix mode...
authorChet Ramey <chet.ramey@case.edu>
Mon, 25 Sep 2023 19:08:04 +0000 (15:08 -0400)
committerChet Ramey <chet.ramey@case.edu>
Mon, 25 Sep 2023 19:08:04 +0000 (15:08 -0400)
56 files changed:
CWRU/CWRU.chlog
MANIFEST
builtins/bind.def
builtins/command.def
builtins/getopts.def
doc/bashref.texi
execute_cmd.c
pcomplete.c
redir.c
tests/alias.right
tests/alias.tests
tests/arith.right
tests/arith.tests
tests/arith9.sub [new file with mode: 0644]
tests/array.right
tests/array16.sub
tests/braces.right
tests/braces.tests
tests/builtins.right
tests/builtins.tests
tests/builtins8.sub
tests/builtins9.sub [new file with mode: 0644]
tests/comsub-eof.right
tests/comsub-eof0.sub
tests/comsub.right
tests/comsub.tests
tests/cond-error1.sub [new file with mode: 0644]
tests/cond-xtrace1.sub [new file with mode: 0644]
tests/cond.right
tests/cond.tests
tests/errors.right
tests/errors.tests
tests/errors4.sub
tests/glob.right
tests/glob.tests
tests/glob11.sub [new file with mode: 0644]
tests/heredoc.right
tests/heredoc.tests
tests/invocation.right [new file with mode: 0644]
tests/invocation.tests [new file with mode: 0644]
tests/posixpipe.right
tests/posixpipe.tests
tests/quote.right
tests/quote.tests
tests/redir.right
tests/redir.tests
tests/run-invocation [new file with mode: 0644]
tests/set-e.right
tests/set-e.tests
tests/time.tests
tests/trap.right
tests/trap.tests
tests/trap8.sub [new file with mode: 0644]
tests/vredir.right
tests/vredir.tests
tests/vredir8.sub

index 88ddf9c948fc3a14a9f1dbce06fe51cce4698ff5..e34b4179930bc9781b460655a6bec1af36a13e27 100644 (file)
@@ -7652,3 +7652,28 @@ lib/readline/readline.h
 
 lib/readline/doc/rltech.texi
        - rl_reparse_colors: document as public function
+
+                                  9/21
+                                  ----
+pcomplete.c
+       - it_init_aliases: move the free (alias_list) inside #ifdef ALIAS.
+         Report and fix from Mike Jonkmans <bashbug@jonkmans.nl>
+
+redir.c
+       - redirection_error: set W_NOPROCSUB in the word redirection_error
+         creates to call redirection_expand
+
+builtins/bind.def
+        - bind_builtin: use CASE_HELPOPT so the long doc gets printed when
+          --help is supplied
+
+builtins/getopts.def
+       - getopts_builtin: change to use no_options()
+
+                                  9/22
+                                  ----
+execute_cmd.c
+       - execute_select_command: in posix mode, an invalid selection variable
+         name is a fatal error, just like with `for'. This is compatible with
+         ksh93 and mksh
+
index 148b61721dd1470cdfcb1b5d029e1ab9fd774425..85b0040380b96502c362d8b261b1585de868b244 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -950,6 +950,7 @@ tests/arith5.sub    f
 tests/arith6.sub       f
 tests/arith7.sub       f
 tests/arith8.sub       f
+tests/arith9.sub       f
 tests/array.tests      f
 tests/array.right      f
 tests/array1.sub       f
@@ -1023,6 +1024,7 @@ tests/builtins5.sub       f
 tests/builtins6.sub    f
 tests/builtins7.sub    f
 tests/builtins8.sub    f
+tests/builtins9.sub    f
 tests/source1.sub      f
 tests/source2.sub      f
 tests/source3.sub      f
@@ -1075,9 +1077,11 @@ tests/comsub-posix5.sub  f
 tests/comsub-posix6.sub        f
 tests/cond.tests       f
 tests/cond.right       f
+tests/cond-error1.sub  f
 tests/cond-regexp1.sub f
 tests/cond-regexp2.sub f
 tests/cond-regexp3.sub f
+tests/cond-xtrace1.sub f
 tests/coproc.tests     f
 tests/coproc.right     f
 tests/cprint.tests     f
@@ -1216,6 +1220,7 @@ tests/glob7.sub           f
 tests/glob8.sub                f
 tests/glob9.sub                f
 tests/glob10.sub       f
+tests/glob11.sub       f
 tests/glob.right       f
 tests/globstar.tests   f
 tests/globstar.right   f
@@ -1271,6 +1276,8 @@ tests/intl2.sub           f
 tests/intl3.sub                f
 tests/intl4.sub                f
 tests/intl.right       f
+tests/invocation.tests f
+tests/invocation.right f
 tests/iquote.tests     f
 tests/iquote.right     f
 tests/iquote1.sub      f
@@ -1487,6 +1494,7 @@ tests/run-ifs             f
 tests/run-ifs-posix    f
 tests/run-input-test   f
 tests/run-intl         f
+tests/run-invocation   f
 tests/run-iquote       f
 tests/run-invert       f
 tests/run-jobs         f
@@ -1559,6 +1567,7 @@ tests/trap4.sub           f
 tests/trap5.sub                f
 tests/trap6.sub                f
 tests/trap7.sub                f
+tests/trap8.sub                f
 tests/type.tests       f
 tests/type.right       f
 tests/type1.sub                f
index 3cf9015415924f5bcd69db8ff4540255142f3b09..e52e1cb0626be8c48da45cf69a866384956ecf7f 100644 (file)
@@ -184,7 +184,7 @@ bind_builtin (WORD_LIST *list)
        case 'X':
          flags |= XXFLAG;
          break;
-       case GETOPT_HELP:
+       CASE_HELPOPT;
        default:
          builtin_usage ();
          BIND_RETURN (EX_USAGE);
index b5f0e188bd20edd056f586295d5fbefbf43930be..4f980592a03e8ecb32721e892ef554fb08075d9d 100644 (file)
@@ -124,6 +124,10 @@ command_builtin (WORD_LIST *list)
 
 #define COMMAND_BUILTIN_FLAGS (CMD_NO_FUNCTIONS | CMD_INHIBIT_EXPANSION | CMD_COMMAND_BUILTIN | (use_standard_path ? CMD_STDPATH : 0))
 
+  /* This code isn't executed any more; look at execute_cmd.c:execute_simple_command()
+     where command is treated as a pseudo-reserved prefix so we can optimize
+     away forks where possible. */
+
   /* We don't want this to be reparsed (consider command echo 'foo &'), so
      just make a simple_command structure and call execute_command with it. */
   command = make_bare_simple_command (line_number);
@@ -134,8 +138,8 @@ command_builtin (WORD_LIST *list)
 
   add_unwind_protect (uw_dispose_command, command);
   result = execute_command (command);
+  dispose_command (command);
 
-  run_unwind_frame ("command_builtin");
-
+  discard_unwind_frame ("command_builtin");
   return (result);
 }
index b8cbc6545604004fee181572ce377e8dfd7889fa..3365ce1dfda39d7105655d0d52e89b94e06c168f 100644 (file)
@@ -312,23 +312,16 @@ getopts_builtin (WORD_LIST *list)
   char **av;
   int ac, ret;
 
+  if (no_options (list))
+    return (EX_USAGE);
+  list = loptend;      /* skip over possible `--' */
+
   if (list == 0)
     {
       builtin_usage ();
       return EX_USAGE;
     }
 
-  reset_internal_getopt ();
-  if ((ret = internal_getopt (list, "")) != -1)
-    {
-      if (ret == GETOPT_HELP)
-       builtin_help ();
-      else
-       builtin_usage ();
-      return (EX_USAGE);
-    }
-  list = loptend;
-
   av = make_builtin_argv (list, &ac);
   ret = dogetopts (ac, av);
   free ((char *)av);
index dd143de392ab6be724cea1c5203941aea3a6f86b..156247ed45a3fefc6206cdb590594b65cc835dd3 100644 (file)
@@ -8598,7 +8598,7 @@ command in which the error occurred").
 @item
 A non-interactive shell exits with an error status if the iteration
 variable in a @code{for} statement or the selection variable in a
-@code{select} statement is a readonly variable.
+@code{select} statement is a readonly variable or has an invalid name.
 
 @item
 Non-interactive shells exit if @var{filename} in @code{.} @var{filename}
index d54fa7f0a5d3484d2e7136cf8d1e92c9d9d8cc25..73723db534b9535689cfefba84df529ad7f93db7 100644 (file)
@@ -3416,7 +3416,14 @@ execute_select_command (SELECT_COM *select_command)
   int retval, list_len, show_menu, save_line_number;
 
   if (check_identifier (select_command->name, 1) == 0)
-    return (EXECUTION_FAILURE);
+    {
+      if (posixly_correct && interactive_shell == 0)
+       {
+         last_command_exit_value = EX_BADUSAGE;
+         jump_to_top_level (ERREXIT);
+       }
+      return (EXECUTION_FAILURE);
+    }
 
   save_line_number = line_number;
   line_number = select_command->line;
index e6c2160041b1485c0c1d12a5e06ca729c6751637..aa6a0440b20c65fe21bc9d6d046f24c80a384060 100644 (file)
@@ -365,10 +365,10 @@ it_init_aliases (ITEMLIST *itp)
   sl->list[n] = (char *)NULL;
   sl->list_size = sl->list_len = n;
   itp->slist = sl;
+  free (alias_list);
 #else
   itp->slist = (STRINGLIST *)NULL;
 #endif
-  free (alias_list);
   return 1;
 }
 
diff --git a/redir.c b/redir.c
index 267a9fc8bf11e5ca47a8ccde4b0b8b402ce91f68..ee66f5cb0564f928d08df39feb8c9a20a0fbb422 100644 (file)
--- a/redir.c
+++ b/redir.c
@@ -183,7 +183,7 @@ redirection_error (REDIRECT *temp, int error, char *fn)
       oflags = temp->redirectee.filename->flags;
       if (posixly_correct && interactive_shell == 0)
        temp->redirectee.filename->flags |= W_NOGLOB;
-      temp->redirectee.filename->flags |= W_NOCOMSUB;
+      temp->redirectee.filename->flags |= W_NOCOMSUB|W_NOPROCSUB;
       filename = allocname = redirection_expand (temp->redirectee.filename);
       temp->redirectee.filename->flags = oflags;
       if (filename == 0)
index 7b883c7d8256ebf85c6ecc12435609f307876e14..d5c53f41c93ad9a37217104657cc7c2a14095eef 100644 (file)
@@ -1,6 +1,7 @@
 alias: 0
 alias: 0
 ./alias.tests: line 38: qfoo: command not found
+./alias.tests: line 44: unalias: foo: not found
 quux
 hi
 declare -a m=([0]="x")
index c3a66f10266984e8ba41e84d705658679c33d5f0..14d3c63f47bebfef49fc6d94cf3de5b482c911d3 100644 (file)
@@ -40,6 +40,8 @@ qfoo
 unalias qfoo qbar qbaz quux
 
 unalias -a
+# error
+unalias foo
 
 alias foo='echo '
 alias bar=baz
index 75c12001370a6f70f06e016258fd2142455c8bb3..e17a127a038d4b410e61fceb1af3f57cf7b65d8e 100644 (file)
@@ -51,6 +51,7 @@
 1
 1
 32
+32
 4
 20
 1,i+=2
@@ -60,7 +61,7 @@
 1,i+=2
 30
 1,j+=2
-./arith.tests: line 127: 1 ? 20 : x+=2: attempted assignment to non-variable (error token is "+=2")
+./arith.tests: line 129: 1 ? 20 : x+=2: attempted assignment to non-variable (error token is "+=2")
 20
 6
 6,5,3
@@ -70,6 +71,8 @@
 127
 36
 40
+40
+40
 10
 10
 10
 36
 62
 63
-./arith.tests: line 162: 3425#56: invalid arithmetic base (error token is "3425#56")
-./arith.tests: line 165: 2#: invalid integer constant (error token is "2#")
-./arith.tests: line 168: 7 = 43 : attempted assignment to non-variable (error token is "= 43 ")
-./arith.tests: line 169: 2#44: value too great for base (error token is "2#44")
-./arith.tests: line 170: 44 / 0 : division by 0 (error token is "0 ")
-./arith.tests: line 171: let: jv += $iv: arithmetic syntax error: operand expected (error token is "$iv")
-./arith.tests: line 172: jv += $iv : arithmetic syntax error: operand expected (error token is "$iv ")
-./arith.tests: line 173: let: rv = 7 + (43 * 6: missing `)' (error token is "6")
-./arith.tests: line 177: 0#4: invalid number (error token is "0#4")
-./arith.tests: line 178: 2#110#11: invalid number (error token is "2#110#11")
+./arith.tests: line 168: 3425#56: invalid arithmetic base (error token is "3425#56")
+./arith.tests: line 171: 2#: invalid integer constant (error token is "2#")
+./arith.tests: line 174: 7 = 43 : attempted assignment to non-variable (error token is "= 43 ")
+./arith.tests: line 175: 2#44: value too great for base (error token is "2#44")
+./arith.tests: line 176: 44 / 0 : division by 0 (error token is "0 ")
+./arith.tests: line 177: let: jv += $iv: arithmetic syntax error: operand expected (error token is "$iv")
+./arith.tests: line 178: jv += $iv : arithmetic syntax error: operand expected (error token is "$iv ")
+./arith.tests: line 179: let: rv = 7 + (43 * 6: missing `)' (error token is "6")
+./arith.tests: line 182: b / 0 : division by 0 (error token is "0 ")
+./arith.tests: line 183: b /= 0 : division by 0 (error token is "0 ")
+./arith.tests: line 188: 0#4: invalid number (error token is "0#4")
+./arith.tests: line 189: 2#110#11: invalid number (error token is "2#110#11")
 abc
 def
 ghi
@@ -97,15 +102,15 @@ ok
 6
 1
 0
-./arith.tests: line 196: 4 + : arithmetic syntax error: operand expected (error token is "+ ")
+./arith.tests: line 207: 4 + : arithmetic syntax error: operand expected (error token is "+ ")
 16
-./arith.tests: line 201: 4 ? : 3 + 5 : expression expected (error token is ": 3 + 5 ")
-./arith.tests: line 202: 1 ? 20 : `:' expected for conditional expression (error token is "20 ")
-./arith.tests: line 203: 4 ? 20 : : expression expected (error token is ": ")
+./arith.tests: line 212: 4 ? : 3 + 5 : expression expected (error token is ": 3 + 5 ")
+./arith.tests: line 213: 1 ? 20 : `:' expected for conditional expression (error token is "20 ")
+./arith.tests: line 214: 4 ? 20 : : expression expected (error token is ": ")
 9
-./arith.tests: line 209: 0 && B=42 : attempted assignment to non-variable (error token is "=42 ")
+./arith.tests: line 220: 0 && B=42 : attempted assignment to non-variable (error token is "=42 ")
 9
-./arith.tests: line 212: 1 || B=88 : attempted assignment to non-variable (error token is "=88 ")
+./arith.tests: line 223: 1 || B=88 : attempted assignment to non-variable (error token is "=88 ")
 9
 0
 9
@@ -121,6 +126,7 @@ ok
 131072
 2147483647
 1
+./arith.tests: line 255: 2**-1 : exponent less than 0 (error token is "1 ")
 4
 4
 5
@@ -131,16 +137,17 @@ ok
 4
 4
 7
-./arith.tests: line 260: 7-- : arithmetic syntax error: operand expected (error token is "- ")
-./arith.tests: line 262: --x=7 : attempted assignment to non-variable (error token is "=7 ")
-./arith.tests: line 263: ++x=7 : attempted assignment to non-variable (error token is "=7 ")
-./arith.tests: line 265: x++=7 : attempted assignment to non-variable (error token is "=7 ")
-./arith.tests: line 266: x--=7 : attempted assignment to non-variable (error token is "=7 ")
+./arith.tests: line 274: 7-- : arithmetic syntax error: operand expected (error token is "- ")
+./arith.tests: line 276: --x=7 : attempted assignment to non-variable (error token is "=7 ")
+./arith.tests: line 277: ++x=7 : attempted assignment to non-variable (error token is "=7 ")
+./arith.tests: line 279: x++=7 : attempted assignment to non-variable (error token is "=7 ")
+./arith.tests: line 280: x--=7 : attempted assignment to non-variable (error token is "=7 ")
 4
 7
 -7
 7
 7
+./arith.tests: line 292: --x++ : ++: assignment requires lvalue (error token is "++ ")
 2
 2
 ./arith1.sub: line 15: 4-- : arithmetic syntax error: operand expected (error token is "- ")
@@ -249,15 +256,40 @@ efg
 0
 0
 0
+./arith9.sub: line 4: a: unbound variable
+./arith9.sub: line 5: a: unbound variable
+0
+after 3 0
+0
+after 4 0
+./arith9.sub: line 14: b: expression recursion level exceeded (error token is "b")
++ var=42
++ echo 42
+42
++ echo 0
+0
++ echo 0
+0
++ echo 0
+0
++ ((  42  ))
++ echo 0
+0
++ ((    ))
++ echo 1
+1
++ set +x
+./arith9.sub: line 37: 4+: arithmetic syntax error: operand expected (error token is "+")
+x = 4+ y =
 8 12
-./arith.tests: line 310: ((: x=9 y=41 : arithmetic syntax error in expression (error token is "y=41 ")
-./arith.tests: line 314: a b: arithmetic syntax error in expression (error token is "b")
-./arith.tests: line 315: ((: a b: arithmetic syntax error in expression (error token is "b")
+./arith.tests: line 332: ((: x=9 y=41 : arithmetic syntax error in expression (error token is "y=41 ")
+./arith.tests: line 336: a b: arithmetic syntax error in expression (error token is "b")
+./arith.tests: line 337: ((: a b: arithmetic syntax error in expression (error token is "b")
 42
 42
 42
 42
 42
 42
-./arith.tests: line 330: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
-./arith.tests: line 333: b[c]d: arithmetic syntax error in expression (error token is "d")
+./arith.tests: line 352: 'foo' : arithmetic syntax error: operand expected (error token is "'foo' ")
+./arith.tests: line 355: b[c]d: arithmetic syntax error in expression (error token is "d")
index e9ab57651a5d7b68799800eb38a591b1b85a84f9..fec2afd02728a0ab5c0e29ad835c52a3a1aa59e0 100644 (file)
@@ -97,6 +97,8 @@ echo $(( 4<(2+3) ? 1 : 32))
 echo $(( (2+2)<(2+3) ? 1 : 32))
 echo $(( (2+2)>(2+3) ? 1 : 32))
 
+echo $(( (2+2)>(2+3) ? 2**0 : 32))
+
 # bug in bash versions through bash-3.2
 S=105
 W=$((S>99?4:S>9?3:S>0?2:0))
@@ -143,6 +145,10 @@ echo $(( 16#FF/2 ))
 echo $(( 8#44 ))
 
 echo $(( 8 ^ 32 ))
+a=8
+echo $(( a ^ 32 ))
+echo $(( a ^= 32 ))
+unset -v a
 
 # other bases
 echo $(( 16#a ))
@@ -172,6 +178,11 @@ let 'jv += $iv'
 echo $(( jv += \$iv ))
 let 'rv = 7 + (43 * 6'
 
+b=44
+echo $(( b / 0 ))
+echo $(( b /= 0 ))
+unset -v b
+
 # more errors
 declare -i i
 i=0#4
@@ -240,6 +251,9 @@ echo $(( 2**16*2 ))
 echo $(( 2**31-1))
 echo $(( 2**0 ))
 
+# error
+echo $(( 2**-1 ))
+
 # {pre,post}-{inc,dec}rement and associated errors
 
 x=4
@@ -273,6 +287,11 @@ echo $(( -7 ))
 echo $(( ++7 ))
 echo $(( --7 ))
 
+unset -v x
+x=8
+echo $(( --x++ ))      # error
+unset -v x
+
 # combinations of expansions
 echo $(( "`echo 1+1`" ))
 echo $(( `echo 1+1` ))
@@ -299,6 +318,9 @@ ${THIS_SH} ./arith7.sub
 # problems with evaluation of conditional expressions
 ${THIS_SH} ./arith8.sub
 
+# expressions with unset variables and nounset enabled
+${THIS_SH} ./arith9.sub
+
 x=4
 y=7
 
diff --git a/tests/arith9.sub b/tests/arith9.sub
new file mode 100644 (file)
index 0000000..811139e
--- /dev/null
@@ -0,0 +1,38 @@
+# test expression evaluation with unset variables
+set -u
+
+( echo $(( a > 4 )) ; echo after 1 )   # error
+( echo $(( a[0] > 4 )); echo after 2)  # error
+
+set +u
+( echo $(( a > 4 )) ; echo after 3 $? )
+( echo $(( a[0] > 4 )); echo after 4 $?)
+
+# this is a recursion stack error
+a=b
+b=a
+echo $(( a + 7 ))
+
+# make sure command printing works for arithmetic expansions and commands
+set -x
+var=42
+
+echo $(( $var ))
+echo $?
+
+echo $(( $null ))
+echo $?
+
+(( $var ))
+echo $?
+
+(( $null ))
+echo $?
+
+set +x
+
+# invalid expressions in different cases
+x=4+
+declare -i x
+x+=7 y=4
+echo x = $x y = $y
index 1889facb26bc5a494e6a0d2a53b5759580a85fb2..b16870dc644cdee5ddb2ccd5a5630966880ea27b 100644 (file)
@@ -399,6 +399,10 @@ bar: array with element zero unset: ok
 bar: element zero: ok
 qux: unset array: ok
 qux: unset array element 0: ok
+1
+0
+0
+0
 2
 2
 2
index b82dbca284b0eac8017cb2efe6ed71786996ab25..94013ea2fe7561fb45504261dca9270bfab62cd6 100644 (file)
@@ -32,3 +32,12 @@ bar[1]=set
 typeset -a qux
 [[ -v qux ]] || echo qux: unset array: ok
 [[ -v qux[0] ]] || echo qux: unset array element 0: ok
+
+unset -v a
+a[1]=set
+
+[[ -v a ]] ; echo $?
+[[ -v a[1] ]] ; echo $?
+[[ -v a[@] ]] ; echo $?
+
+[[ ${#a[@]} > 0 ]]; echo $?
index 401754647867b707747d4dfc7934930cbd38bd09..75be33e81af7a6fd432b57039d7e781c932d5a77 100644 (file)
@@ -58,6 +58,8 @@ a b c d e f g h i j k l m n o p q r s t u v w x y z
 a c e g i k m o q s u w y
 z x v t r p n l j h f d b
 2147483645 2147483646 2147483647 2147483648 2147483649
+00 01 02 03 04 05 06 07 08 09 10
+00 02 04 06 08 10
 10 8 6 4 2 0
 10 8 6 4 2 0
 -50 -45 -40 -35 -30 -25 -20 -15 -10 -5 0
index da0b624bce1b2542f23ef4dd01797a8c3af5c8b0..56a08166ad05bdf1319bf74b5424eab6df2dfa4b 100644 (file)
@@ -110,6 +110,10 @@ echo {z..a..-2}
 # make sure brace expansion handles ints > 2**31 - 1 using intmax_t
 echo {2147483645..2147483649}
 
+# want zero-padding here
+echo {00..10}
+echo {00..10..2}
+
 # unwanted zero-padding -- fixed post-bash-4.0
 echo {10..0..2}
 echo {10..0..-2}
index 58d3b99cca82135c223c3190225f86fb1583ec0f..e0b11ac4c4773beb5cdcb487e5a8e4932defe6cf 100644 (file)
@@ -291,4 +291,21 @@ u=rwx,g=rwx,o=rwx
 u=rwx,g=rwx,o=rwx
 u=rwx,g=rx,o=rx
 u=rwx,g=rx,o=rx
-./builtins.tests: line 287: exit: status: numeric argument required
+hash: hash table empty
+./builtins9.sub: line 19: hash: notthere: not found
+1
+/nosuchdir/nosuchfile
+builtin hash -p /nosuchdir/nosuchfile cat
+builtin hash -p /nosuchdir/nosuchfile cat
+./builtins9.sub: line 30: hash: notthere: not found
+./builtins9.sub: line 32: hash: notthere: not found
+./builtins9.sub: line 33: hash: notthere: not found
+1
+./builtins9.sub: line 40: /nosuchdir/nosuchfile: No such file or directory
+127
+/nosuchdir/nosuchfile
+0
+0
+found
+./builtins9.sub: line 52: hash: /: Is a directory
+./builtins.tests: line 290: exit: status: numeric argument required
index 50fdbaba4312924dd91d5269f0e02d98990e3360..a09248692d431bb0b0e64414ee693954c2a5bc15 100644 (file)
@@ -283,6 +283,9 @@ ${THIS_SH} ./builtins7.sub
 # POSIX complete symbolic umask tests
 ${THIS_SH} ./builtins8.sub
 
+# hash tests
+${THIS_SH} ./builtins9.sub
+
 # this must be last -- it is a fatal error
 exit status
 
index 1c1b133fe9bd5a85d4d59da37a5ad41f44d9ed58..8b049c09a3f1836fbe28d4c5ac751837bb346deb 100644 (file)
@@ -1,3 +1,17 @@
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
 umask 022
 umask u=r+w
 umask -S
@@ -49,6 +63,3 @@ umask -S
 umask 022
 umask a+xr
 umask -S
-
-
-
diff --git a/tests/builtins9.sub b/tests/builtins9.sub
new file mode 100644 (file)
index 0000000..d8f6c97
--- /dev/null
@@ -0,0 +1,52 @@
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# hash printing, deleting tests
+hash -r        # start with empty hash table
+hash   # should be error/warning
+
+hash -d notthere
+echo $?
+
+hash -p /nosuchdir/nosuchfile cat
+
+hash -t cat
+hash -lt cat
+hash -l
+
+hash -d cat
+
+hash -d notthere
+
+hash -lt notthere
+hash -t notthere
+
+hash -t cat 2>/dev/null
+echo $?
+
+# this should fail
+hash -p /nosuchdir/nosuchfile cat
+cat </dev/null
+echo $?
+hash -t cat
+echo $?
+
+# but with checkhash set, it should not
+shopt -s checkhash
+cat </dev/null
+echo $?
+{ hash -t cat | grep cat >/dev/null; } && echo found
+
+hash -r
+hash -p / root
index cd5ab69231ab4cfd6a18c432fd92b832f794220d..c6a4c9ef4a9966fdb355b3933a41c184f2b50c41 100644 (file)
@@ -1,4 +1,6 @@
-./comsub-eof0.sub: line 5: warning: here-document at line 3 delimited by end-of-file (wanted `EOF')
+./comsub-eof0.sub: line 4: warning: here-document at line 2 delimited by end-of-file (wanted `EOF')
+hi
+./comsub-eof0.sub: line 11: warning: here-document at line 9 delimited by end-of-file (wanted `EOF')
 hi
 hi
 ./comsub-eof2.sub: line 2: warning: here-document at line 1 delimited by end-of-file (wanted `EOF')
index 7490faabc0786f99998c24699351b24db5885128..1cbbb819aebe0a27bdf2f690ea69f24e432574b9 100644 (file)
@@ -1,3 +1,9 @@
+# this works as it should, but with a warning
+foo=$(cat <<EOF
+hi
+EOF)
+echo $foo
+unset -v foo
 # it's only the space before the paren that makes this an error
 # when I fix it, it will show up here
 foo=$(cat <<EOF
index 0c84094cf90096a0f113ce8a05acdb19930be8d6..4a5039d6790fd46c47c1c7df4c426c4c4b19735b 100644 (file)
@@ -20,6 +20,10 @@ argv[1] = <foo\^Jbar>
 argv[1] = <foobar>
 argv[1] = <foo\^Jbar>
 nested
+blank ----
+blank ----
+blank ----
+blank ----
 #esac
 a
 ok 1
index 8b89ce44d286b484e2f63328237bc42f6778a205..5969f6ca6da616ac34ba85d96a1ac7eabe0a9d5a 100644 (file)
@@ -76,6 +76,16 @@ echo $(echo $( echo nested )
 )
 )
 
+# empty comsubs, fork and nofork
+echo blank --$(
+)--
+echo blank --$()--
+
+echo blank --${ 
+}--
+echo blank --${  }--
+
+
 BUILDDIR=/builds/test
 read << EOC
 Dir: ${BUILDDIR#<(echo a)/}
diff --git a/tests/cond-error1.sub b/tests/cond-error1.sub
new file mode 100644 (file)
index 0000000..f04f775
--- /dev/null
@@ -0,0 +1,20 @@
+: ${THIS_SH:=./bash}
+
+# all parse errors
+${THIS_SH} -c '[[ ( -n xx' bash
+${THIS_SH} -c '[[ ( -n xx )' bash
+
+${THIS_SH} -c '[[ ( -t X ) ]' bash
+
+${THIS_SH} -c '[[ -n &' bash
+${THIS_SH} -c '[[ -n XX &' bash
+${THIS_SH} -c '[[ -n XX & ]' bash
+
+${THIS_SH} -c '[[ 4 & ]]' bash
+${THIS_SH} -c '[[ 4 > & ]]' bash
+
+${THIS_SH} -c '[[ & ]]' bash
+${THIS_SH} -c '[[ -Q 7 ]]' bash
+${THIS_SH} -c '[[ -n < ]]' bash
+
+
diff --git a/tests/cond-xtrace1.sub b/tests/cond-xtrace1.sub
new file mode 100644 (file)
index 0000000..e7bf685
--- /dev/null
@@ -0,0 +1,19 @@
+# printing conditional commands for xtrace
+
+set -x
+
+# error
+[[ -t X ]]
+# null operand
+[[ $b > 7 ]]
+
+# successful unary operator
+[[ -n X ]]
+
+# successful binary operator
+ivar=42
+[[ $ivar -eq 42 ]]
+
+# compound operator, displayed as two unary expressions
+
+[[ -n a && -n b ]]
index 1b0e8c7435bf3f472a211782b82ca54cbd5fb153..cbe552b2a355888d6871f56260925e4a33b829a6 100644 (file)
@@ -147,3 +147,42 @@ ok 5
 ok 6
 ok 7
 ok 8
+bash: -c: line 1: unexpected token `EOF', expected `)'
+bash: -c: line 2: syntax error: unexpected end of file
+bash: -c: line 1: unexpected EOF while looking for `]]'
+bash: -c: line 2: syntax error: unexpected end of file
+bash: -c: line 1: syntax error in conditional expression
+bash: -c: line 1: syntax error near `]'
+bash: -c: line 1: `[[ ( -t X ) ]'
+bash: -c: line 1: unexpected argument `&' to conditional unary operator
+bash: -c: line 1: syntax error near `&'
+bash: -c: line 1: `[[ -n &'
+bash: -c: line 1: syntax error in conditional expression: unexpected token `&'
+bash: -c: line 1: syntax error near `&'
+bash: -c: line 1: `[[ -n XX &'
+bash: -c: line 1: syntax error in conditional expression: unexpected token `&'
+bash: -c: line 1: syntax error near `&'
+bash: -c: line 1: `[[ -n XX & ]'
+bash: -c: line 1: unexpected token `&', conditional binary operator expected
+bash: -c: line 1: syntax error near `&'
+bash: -c: line 1: `[[ 4 & ]]'
+bash: -c: line 1: unexpected argument `&' to conditional binary operator
+bash: -c: line 1: syntax error near `&'
+bash: -c: line 1: `[[ 4 > & ]]'
+bash: -c: line 1: unexpected token `&' in conditional command
+bash: -c: line 1: syntax error near `&'
+bash: -c: line 1: `[[ & ]]'
+bash: -c: line 1: conditional binary operator expected
+bash: -c: line 1: syntax error near `7'
+bash: -c: line 1: `[[ -Q 7 ]]'
+bash: -c: line 1: unexpected argument `<' to conditional unary operator
+bash: -c: line 1: syntax error near `<'
+bash: -c: line 1: `[[ -n < ]]'
++ [[ -t X ]]
+./cond-xtrace1.sub: line 6: [[: X: integer expected
++ [[ '' > 7 ]]
++ [[ -n X ]]
++ ivar=42
++ [[ 42 -eq 42 ]]
++ [[ -n a ]]
++ [[ -n b ]]
index 020be32b212a2377bbf4c9b44c9b4274c0b4207d..68f168649acdc500677c264878b8206bcdafdfad 100644 (file)
@@ -230,7 +230,8 @@ del=$'\177'
 if [[ str ]] then [[ str ]] fi
 
 ${THIS_SH} ./cond-regexp1.sub
-
 ${THIS_SH} ./cond-regexp2.sub
-
 ${THIS_SH} ./cond-regexp3.sub
+
+${THIS_SH} ./cond-error1.sub
+${THIS_SH} ./cond-xtrace1.sub
index 2df2c7e74e703c1d00aeed4d1ca059a552227fac..a95d00807995302cfa962b502d198fe212faba94 100644 (file)
@@ -5,101 +5,113 @@ unalias: usage: unalias [-a] name [name ...]
 ./errors.tests: line 32: alias: hoowah: not found
 ./errors.tests: line 33: unalias: hoowah: not found
 ./errors.tests: line 36: `1': not a valid identifier
+./errors.tests: line 37: `f\1': not a valid identifier
+./errors.tests: line 41: `invalid-name': not a valid identifier
+./errors.tests: line 43: `f\1': not a valid identifier
+./errors.tests: line 46: `1': not a valid identifier
+./errors.tests: line 47: `f\1': not a valid identifier
+./errors.tests: line 48: `invalid-name': not a valid identifier
+./errors.tests: line 50: `1': not a valid identifier
+./errors.tests: line 51: `f\1': not a valid identifier
 declare -fr func
-./errors.tests: line 49: func: readonly function
-./errors.tests: line 52: unset: -x: invalid option
+./errors.tests: line 64: func: readonly function
+./errors.tests: line 67: unset: -x: invalid option
 unset: usage: unset [-f] [-v] [-n] [name ...]
-./errors.tests: line 55: unset: func: cannot unset: readonly function
-./errors.tests: line 58: declare: func: readonly function
-./errors.tests: line 62: declare: -a: invalid option
-./errors.tests: line 63: declare: -i: invalid option
-./errors.tests: line 67: unset: XPATH: cannot unset: readonly variable
-./errors.tests: line 73: unset: cannot simultaneously unset a function and a variable
-./errors.tests: line 76: declare: -z: invalid option
+./errors.tests: line 70: unset: func: cannot unset: readonly function
+./errors.tests: line 73: declare: func: readonly function
+./errors.tests: line 77: declare: -a: invalid option
+./errors.tests: line 78: declare: -i: invalid option
+./errors.tests: line 82: unset: XPATH: cannot unset: readonly variable
+./errors.tests: line 88: unset: cannot simultaneously unset a function and a variable
+./errors.tests: line 91: declare: -z: invalid option
 declare: usage: declare [-aAfFgiIlnrtux] [name[=value] ...] or declare -p [-aAfFilnrtux] [name ...]
-./errors.tests: line 78: declare: `-z': not a valid identifier
-./errors.tests: line 79: declare: `/bin/sh': not a valid identifier
-./errors.tests: line 83: declare: cannot use `-f' to make functions
-./errors.tests: line 86: exec: -i: invalid option
+./errors.tests: line 93: declare: `-z': not a valid identifier
+./errors.tests: line 94: declare: `/bin/sh': not a valid identifier
+./errors.tests: line 98: declare: cannot use `-f' to make functions
+./errors.tests: line 101: exec: -i: invalid option
 exec: usage: exec [-cl] [-a name] [command [argument ...]] [redirection ...]
-./errors.tests: line 90: export: XPATH: not a function
-./errors.tests: line 93: break: only meaningful in a `for', `while', or `until' loop
-./errors.tests: line 94: continue: only meaningful in a `for', `while', or `until' loop
-./errors.tests: line 97: shift: label: numeric argument required
-./errors.tests: line 102: shift: too many arguments
-./errors.tests: line 108: let: expression expected
-./errors.tests: line 111: local: can only be used in a function
-./errors.tests: line 114: logout: not login shell: use `exit'
-./errors.tests: line 117: hash: notthere: not found
-./errors.tests: line 120: hash: -v: invalid option
+./errors.tests: line 105: export: XPATH: not a function
+./errors.tests: line 108: break: only meaningful in a `for', `while', or `until' loop
+./errors.tests: line 109: continue: only meaningful in a `for', `while', or `until' loop
+./errors.tests: line 112: shift: label: numeric argument required
+./errors.tests: line 117: shift: too many arguments
+./errors.tests: line 123: let: expression expected
+./errors.tests: line 126: local: can only be used in a function
+./errors.tests: line 129: logout: not login shell: use `exit'
+./errors.tests: line 132: hash: notthere: not found
+./errors.tests: line 135: hash: -v: invalid option
 hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
-./errors.tests: line 124: hash: hashing disabled
-./errors.tests: line 127: export: `AA[4]': not a valid identifier
-./errors.tests: line 128: readonly: `AA[4]': not a valid identifier
-./errors.tests: line 131: unset: [-2]: bad array subscript
-./errors.tests: line 135: AA: readonly variable
-./errors.tests: line 139: AA: readonly variable
-./errors.tests: line 147: shift: 5: shift count out of range
-./errors.tests: line 148: shift: -2: shift count out of range
-./errors.tests: line 151: shopt: no_such_option: invalid shell option name
-./errors.tests: line 152: shopt: no_such_option: invalid shell option name
-./errors.tests: line 155: umask: 09: octal number out of range
-./errors.tests: line 156: umask: `:': invalid symbolic mode character
-./errors.tests: line 157: umask: `:': invalid symbolic mode operator
-./errors.tests: line 160: umask: -i: invalid option
+./errors.tests: line 139: hash: hashing disabled
+./errors.tests: line 142: export: `AA[4]': not a valid identifier
+./errors.tests: line 143: readonly: `AA[4]': not a valid identifier
+./errors.tests: line 146: unset: [-2]: bad array subscript
+./errors.tests: line 150: AA: readonly variable
+./errors.tests: line 154: AA: readonly variable
+./errors.tests: line 162: shift: 5: shift count out of range
+./errors.tests: line 163: shift: -2: shift count out of range
+./errors.tests: line 166: shopt: no_such_option: invalid shell option name
+./errors.tests: line 167: shopt: no_such_option: invalid shell option name
+./errors.tests: line 170: umask: 09: octal number out of range
+./errors.tests: line 171: umask: `:': invalid symbolic mode character
+./errors.tests: line 172: umask: `:': invalid symbolic mode operator
+./errors.tests: line 175: umask: -i: invalid option
 umask: usage: umask [-p] [-S] [mode]
-./errors.tests: line 164: umask: `p': invalid symbolic mode character
-./errors.tests: line 173: VAR: readonly variable
-./errors.tests: line 176: declare: VAR: readonly variable
-./errors.tests: line 177: declare: VAR: readonly variable
-./errors.tests: line 179: declare: unset: not found
-./errors.tests: line 182: VAR: readonly variable
+./errors.tests: line 179: umask: `p': invalid symbolic mode character
+./errors.tests: line 188: VAR: readonly variable
+./errors.tests: line 191: declare: VAR: readonly variable
+./errors.tests: line 192: declare: VAR: readonly variable
+./errors.tests: line 194: declare: unset: not found
+./errors.tests: line 197: VAR: readonly variable
 comsub: -c: line 1: syntax error near unexpected token `)'
 comsub: -c: line 1: `: $( for z in 1 2 3; do )'
 comsub: -c: line 1: syntax error near unexpected token `done'
 comsub: -c: line 1: `: $( for z in 1 2 3; done )'
-./errors.tests: line 189: cd: HOME not set
-./errors.tests: line 190: cd: /tmp/xyz.bash: No such file or directory
-./errors.tests: line 192: cd: OLDPWD not set
-./errors.tests: line 193: cd: /bin/sh: Not a directory
-./errors.tests: line 195: cd: /tmp/cd-notthere: No such file or directory
-./errors.tests: line 198: .: filename argument required
+./errors.tests: line 204: cd: HOME not set
+./errors.tests: line 205: cd: /tmp/xyz.bash: No such file or directory
+./errors.tests: line 207: cd: OLDPWD not set
+./errors.tests: line 208: cd: /bin/sh: Not a directory
+./errors.tests: line 210: cd: /tmp/cd-notthere: No such file or directory
+./errors.tests: line 213: .: filename argument required
 .: usage: . filename [arguments]
-./errors.tests: line 199: source: filename argument required
+./errors.tests: line 214: source: filename argument required
 source: usage: source filename [arguments]
-./errors.tests: line 202: .: -i: invalid option
+./errors.tests: line 217: .: -i: invalid option
 .: usage: . filename [arguments]
-./errors.tests: line 205: set: -q: invalid option
+./errors.tests: line 220: set: -q: invalid option
 set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]
-./errors.tests: line 208: enable: sh: not a shell builtin
-./errors.tests: line 208: enable: bash: not a shell builtin
-./errors.tests: line 211: shopt: cannot set and unset shell options simultaneously
-./errors.tests: line 214: read: var: invalid timeout specification
-./errors.tests: line 217: read: `/bin/sh': not a valid identifier
-./errors.tests: line 220: VAR: readonly variable
-./errors.tests: line 223: readonly: -x: invalid option
+./errors.tests: line 223: enable: sh: not a shell builtin
+./errors.tests: line 223: enable: bash: not a shell builtin
+./errors.tests: line 226: shopt: cannot set and unset shell options simultaneously
+./errors.tests: line 229: read: var: invalid timeout specification
+./errors.tests: line 232: read: `/bin/sh': not a valid identifier
+./errors.tests: line 235: VAR: readonly variable
+./errors.tests: line 238: readonly: -x: invalid option
 readonly: usage: readonly [-aAf] [name[=value] ...] or readonly -p
-./errors.tests: line 226: eval: -i: invalid option
+./errors.tests: line 241: eval: -i: invalid option
 eval: usage: eval [arg ...]
-./errors.tests: line 227: command: -i: invalid option
+./errors.tests: line 242: command: -i: invalid option
 command: usage: command [-pVv] command [arg ...]
-./errors.tests: line 230: /bin/sh + 0: arithmetic syntax error: operand expected (error token is "/bin/sh + 0")
-./errors.tests: line 231: /bin/sh + 0: arithmetic syntax error: operand expected (error token is "/bin/sh + 0")
-./errors.tests: line 234: trap: NOSIG: invalid signal specification
-./errors.tests: line 237: trap: -s: invalid option
+./errors.tests: line 245: /bin/sh + 0: arithmetic syntax error: operand expected (error token is "/bin/sh + 0")
+./errors.tests: line 246: /bin/sh + 0: arithmetic syntax error: operand expected (error token is "/bin/sh + 0")
+./errors.tests: line 249: trap: NOSIG: invalid signal specification
+./errors.tests: line 252: trap: -s: invalid option
 trap: usage: trap [-Plp] [[action] signal_spec ...]
-./errors.tests: line 243: return: can only `return' from a function or sourced script
-./errors.tests: line 247: break: 0: loop count out of range
-./errors.tests: line 251: continue: 0: loop count out of range
-./errors.tests: line 256: builtin: bash: not a shell builtin
-./errors.tests: line 260: bg: no job control
-./errors.tests: line 261: fg: no job control
-./errors.tests: line 264: kill: -s: option requires an argument
-./errors.tests: line 266: kill: S: invalid signal specification
-./errors.tests: line 268: kill: `': not a pid or valid job spec
+./errors.tests: line 258: return: can only `return' from a function or sourced script
+./errors.tests: line 262: break: 0: loop count out of range
+./errors.tests: line 266: continue: 0: loop count out of range
+./errors.tests: line 271: builtin: bash: not a shell builtin
+./errors.tests: line 275: bg: no job control
+./errors.tests: line 276: fg: no job control
+./errors.tests: line 279: kill: -s: option requires an argument
+./errors.tests: line 281: kill: S: invalid signal specification
+./errors.tests: line 283: kill: `': not a pid or valid job spec
 kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
-./errors.tests: line 273: set: trackall: invalid option name
-./errors.tests: line 277: xx: readonly variable
+./errors.tests: line 288: set: trackall: invalid option name
+./errors.tests: line 289: set: -q: invalid option
+set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]
+./errors.tests: line 290: set: -i: invalid option
+set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]
+./errors.tests: line 294: xx: readonly variable
 1
 ./errors1.sub: line 14: .: -i: invalid option
 .: usage: . filename [arguments]
@@ -115,7 +127,18 @@ TEST
 2
 ./errors4.sub: line 20: var: readonly variable
 after readonly assignment
-./errors4.sub: line 29: break: x: numeric argument required
+./errors4.sub: line 27: var: readonly variable
+./errors4.sub: line 31: f: readonly variable
+./errors4.sub: line 34: var: readonly variable
+1) 1
+2) 2
+3) 3
+#? ./errors4.sub: line 37: var: readonly variable
+1) 1
+2) 2
+3) 3
+#? ./errors4.sub: line 40: var: readonly variable
+./errors4.sub: line 45: break: x: numeric argument required
 1
 2
 ./errors4.sub: line 20: var: readonly variable
@@ -215,4 +238,4 @@ sh: line 1: unset: `a-b': not a valid identifier
 sh: line 1: /nosuchfile: No such file or directory
 sh: line 1: trap: SIGNOSIG: invalid signal specification
 after trap
-./errors.tests: line 316: `!!': not a valid identifier
+./errors.tests: line 333: `!!': not a valid identifier
index 8161383f05b1c27e42c4c6b1c6bdf5aaec94d6a1..17354dc9185cfef0cccb94908ff6b5c776705df2 100644 (file)
@@ -34,6 +34,21 @@ unalias hoowah
 
 # the iteration variable must be a valid identifier
 for 1 in a b c; do echo $1; done
+for f\1 in a b c ; do echo $f ; done
+
+# in posix mode, it's a fatal error
+(set -o posix
+for invalid-name in a b c; do echo $1; done; echo after posix for)
+(set -o posix
+for f\1 in a b c ; do echo $f ; done; echo after posix for 2)
+
+# same with select
+select 1 in a b c; do echo $REPLY; done
+select f\1 in a b c ; do echo $REPLY ; done
+select invalid-name in a b c; do echo $REPLY; done
+
+(set -o posix ; select 1 in a b c; do echo $REPLY; done; echo after posix select)
+(set -o posix ; select f\1 in a b c ; do echo $REPLY ; done ; echo after posix select 2)
 
 # try to rebind a read-only function
 func()
@@ -271,6 +286,8 @@ kill -INT
 
 # bad shell option names
 set -o trackall                # bash is not ksh
+set -q                 # this is an error
+set -i                 # this is not allowed
 
 # problem with versions through bash-4.2
 readonly xx=5
index 6b40502454530ae4a89ff240fa01af1259fc2fd6..5ee6d583dbf2c3694e75d7bcc157781ca6a08b18 100644 (file)
@@ -23,6 +23,22 @@ for num in 1 2 3 4 5; do
 done 
 echo after readonly assignment
 
+# can't have the variable in a for command be readonly
+for var in 1 2 3 4 5; do echo $var; done
+
+# but in posix mode these are fatal errors
+(set -o posix
+for f in 1 2 3 4; do readonly f; done ; echo after for readonly assignment)
+
+(set -o posix
+for var in 1 2 3 4; do echo $var; done; echo after posix for readonly variable)
+
+# same with select 
+select var in 1 2 3; do echo $REPLY; done <<<1
+
+(set -o posix
+select var in 1 2 3; do echo $REPLY; done <<<1 ; echo after posix select readonly variable)
+
 # non-numeric arguments to break are fatal errors for all non-interactive shells
 for f in 1 2 3 4 5
 do
index 723ee7b466b991608b69595f8ca592f646695600..4d89de8061375918d3cf1530f02cbe2f8a1f2997 100644 (file)
@@ -125,6 +125,22 @@ a aa b bb
 .a .aa .b .bb a aa b bb
 .a .aa .b .bb
 . .. .a .aa .b .bb
+mailcheck.o make_cmd.o mksignames mksignames.o mksyntax mksyntax.dSYM
+
+mailcheck.o make_cmd.o mksignames mksignames.o mksyntax mksyntax.dSYM
+mksyntax.dSYM mksyntax mksignames.o mksignames make_cmd.o mailcheck.o
+
+mailcheck.o make_cmd.o mksignames mksignames.o mksyntax mksyntax.dSYM
+mailcheck.o make_cmd.o mksignames mksignames.o mksyntax mksyntax.dSYM
+
+mksyntax mksignames make_cmd.o mailcheck.o mksignames.o mksyntax.dSYM
+mksyntax.dSYM mksignames.o mailcheck.o make_cmd.o mksignames mksyntax
+
+mksyntax mksignames make_cmd.o mailcheck.o mksignames.o mksyntax.dSYM
+mksyntax.dSYM mksignames.o mailcheck.o make_cmd.o mksignames mksyntax
+
+mksyntax mksignames make_cmd.o mailcheck.o mksignames.o mksyntax.dSYM
+mksyntax.dSYM mksignames.o mailcheck.o make_cmd.o mksignames mksyntax
 argv[1] = <a>
 argv[2] = <abc>
 argv[3] = <abd>
@@ -139,7 +155,7 @@ argv[2] = <abc>
 argv[3] = <abd>
 argv[4] = <abe>
 tmp/l1 tmp/l2 tmp/*4 tmp/l3
-./glob.tests: line 66: no match: tmp/*4
+./glob.tests: line 67: no match: tmp/*4
 argv[1] = <bdir/>
 argv[1] = <*>
 argv[1] = <a*>
index 02d530261513bca33d02a7beaceff36136132b2c..bdb2b774cc7f4c0c8af6a532346952bf794ceaf3 100644 (file)
@@ -31,6 +31,7 @@ ${THIS_SH} ./glob7.sub
 ${THIS_SH} ./glob8.sub
 ${THIS_SH} ./glob9.sub
 ${THIS_SH} ./glob10.sub
+${THIS_SH} ./glob11.sub
 
 MYDIR=$PWD     # save where we are
 
diff --git a/tests/glob11.sub b/tests/glob11.sub
new file mode 100644 (file)
index 0000000..ff50efa
--- /dev/null
@@ -0,0 +1,69 @@
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# testing GLOBSORT
+LC_COLLATE=C
+LC_CTYPE=C
+LANG=C
+
+: ${TMPDIR:=/tmp}
+
+TDIR=$TMPDIR/glob-$$
+{ mkdir $TDIR && cd $TDIR; } || exit 1
+
+# try to impose some kind of testable ordering
+echo 123 > mksyntax ; sleep 0.1
+echo 123456 > mksignames ; sleep 0.1
+echo 1234567879 > make_cmd.o ; sleep 0.1
+echo 123456789012 > mailcheck.o ; sleep 0.1
+echo 123456789012345 > mksignames.o ; sleep 0.1
+echo 123456789012345678 > mksyntax.dSYM ; sleep 0.1
+
+echo m*
+GLOBSORT=nosort
+#echo m*                       # might have to take this one out
+unset GLOBSORT
+echo
+
+GLOBSORT=
+echo m*
+GLOBSORT='-name'
+echo m*
+echo
+
+GLOBSORT='+nonsense'
+echo m*
+GLOBSORT='-nonsense'
+echo m*
+echo
+
+GLOBSORT='+atime'
+echo m*
+GLOBSORT='-atime'
+echo m*
+echo
+
+GLOBSORT='+mtime'
+echo m*
+GLOBSORT='-mtime'
+echo m*
+echo
+
+GLOBSORT=size
+echo m*
+GLOBSORT=-size
+echo m*
+
+cd $OLDPWD
+rm -rf $TDIR
index 634021388387b5e6858c8ffe6c98529ced6338fa..d5a4a7d7537564aa2919c17369bdb8e8ee3d6102 100644 (file)
@@ -17,14 +17,18 @@ hi\
 there
 EO\
 F
+line 1line 2
 hi
 hi
+nextEOF
 tab 1
 tab 2
 tab 3
 abc
 def ghi
 jkl mno
+echo "
+echo \"
 fff is a function
 fff () 
 { 
@@ -150,6 +154,7 @@ HERE
     done
 }
 comsub here-string
-./heredoc.tests: line 159: warning: here-document at line 157 delimited by end-of-file (wanted `EOF')
+./heredoc.tests: line 181: warning: here-document at line 178 delimited by end-of-file (wanted `')
 hi
 there
+''
index d3da798ddc06d1adc2614c094bd45234bb57980a..2f94d1d721550502db0437bbc1e87d5a787fdcce 100644 (file)
@@ -80,6 +80,12 @@ F
 EOF
 true
 
+# but unquoted here-documents remove backslash-newline
+cat <<EOF
+line 1\
+line 2
+EOF
+
 # check that \newline is removed at start of here-doc
 cat << EO\
 F
@@ -92,6 +98,12 @@ hi
 EO\
 F
 
+# backslash-newline processing is performed before the check for the delimiter
+cat <<EOF
+next\
+EOF
+EOF
+
 # check operation of tab removal in here documents
 cat <<- EOF
        tab 1
@@ -100,16 +112,25 @@ cat <<- EOF
        EOF
 
 # check appending of text to file from here document
-rm -f ${TMPDIR}/bash-zzz
-cat > ${TMPDIR}/bash-zzz << EOF
+rm -f ${TMPDIR}/bash-zzz-$$
+cat > ${TMPDIR}/bash-zzz-$$ << EOF
 abc
 EOF
-cat >> ${TMPDIR}/bash-zzz << EOF
+cat >> ${TMPDIR}/bash-zzz-$$ << EOF
 def ghi
 jkl mno
 EOF
-cat ${TMPDIR}/bash-zzz
-rm -f ${TMPDIR}/bash-zzz
+cat ${TMPDIR}/bash-zzz-$$
+rm -f ${TMPDIR}/bash-zzz-$$
+
+# check behavior of double quotes and backslashes in here-documents
+cat <<EOF
+echo "
+EOF
+
+cat <<EOF
+echo \"
+EOF
 
 # make sure command printing puts the here-document as the last redirection
 # on the line, and the function export code preserves syntactic correctness
@@ -154,6 +175,7 @@ echo $(
 # check that end of file delimits a here-document
 # THIS MUST BE LAST!
 
-cat << EOF
+cat <<''
 hi
 there
+''
diff --git a/tests/invocation.right b/tests/invocation.right
new file mode 100644 (file)
index 0000000..99a82c4
--- /dev/null
@@ -0,0 +1,77 @@
+.: .: Is a directory
+bash: -c: option requires an argument
+bash: --badopt: invalid option
+bash [GNU long option] [option] ...
+bash [GNU long option] [option] script-file ...
+GNU long options:
+       --debug
+       --debugger
+       --dump-po-strings
+       --dump-strings
+       --help
+       --init-file
+       --login
+       --noediting
+       --noprofile
+       --norc
+       --posix
+       --pretty-print
+       --rcfile
+       --restricted
+       --verbose
+       --version
+Shell options:
+       -ilrsD or -c command or -O shopt_option         (invocation only)
+       -abefhkmnptuvxBCEHPT or -o option
+bash: --initfile: invalid option
+bash [GNU long option] [option] ...
+bash [GNU long option] [option] script-file ...
+GNU long options:
+       --debug
+       --debugger
+       --dump-po-strings
+       --dump-strings
+       --help
+       --init-file
+       --login
+       --noediting
+       --noprofile
+       --norc
+       --posix
+       --pretty-print
+       --rcfile
+       --restricted
+       --verbose
+       --version
+Shell options:
+       -ilrsD or -c command or -O shopt_option         (invocation only)
+       -abefhkmnptuvxBCEHPT or -o option
+bash: -q: invalid option
+bash [GNU long option] [option] ...
+bash [GNU long option] [option] script-file ...
+GNU long options:
+       --debug
+       --debugger
+       --dump-po-strings
+       --dump-strings
+       --help
+       --init-file
+       --login
+       --noediting
+       --noprofile
+       --norc
+       --posix
+       --pretty-print
+       --rcfile
+       --restricted
+       --verbose
+       --version
+Shell options:
+       -ilrsD or -c command or -O shopt_option         (invocation only)
+       -abefhkmnptuvxBCEHPT or -o option
+this-bash
+$- for -c includes c
+a
+a
+bad-interp
+./invocation.tests: ./x23: nosuchfile: bad interpreter: No such file or directory
diff --git a/tests/invocation.tests b/tests/invocation.tests
new file mode 100644 (file)
index 0000000..f395289
--- /dev/null
@@ -0,0 +1,62 @@
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+: ${THIS_SH:=./bash}
+
+# invocation modes and errors
+
+export BASH_ARGV0=this-bash
+
+${THIS_SH} .
+
+#${THIS_SH} --version -c 'exit 0' bash
+#${THIS_SH} --help -c 'exit 0' bash
+
+${THIS_SH} -c |& sed 's|^.*/bash|bash|'
+
+${THIS_SH} --badopt |& sed 's|^.*/bash|bash|'
+${THIS_SH} --initfile |& sed 's|^.*/bash|bash|'
+${THIS_SH} -q |& sed 's|^.*/bash|bash|'
+
+${THIS_SH} -c 'echo $0'
+
+{ ${THIS_SH} -c 'echo $-' bash | grep c >/dev/null; } && echo '$- for -c includes c'
+
+: ${TMPDIR:=/tmp}
+TDIR=$TMPDIR/invocation-$$
+mkdir $TDIR || exit 1
+SAVEPWD=$PWD
+
+# script that ends with a comment and no newline
+printf 'echo a # comment' > $TDIR/x23.in
+${THIS_SH} $TDIR/x23.in
+printf 'echo a' > $TDIR/x23.in
+${THIS_SH} $TDIR/x23.in
+rm -f $TDIR/x23.in
+
+# script with invalid interpreter
+cat > $TDIR/x23 <<EOF
+#! nosuchfile
+echo bad-interp
+EOF
+chmod +x $TDIR/x23
+
+# this is fine
+${THIS_SH} $TDIR/x23
+command cd -L $TDIR
+# but this results in a bad-interpreter error
+./x23
+
+cd $SAVEPWD
+rm -rf $TDIR
index 8f6c9cbd8ab1632de333dddc110d4a6cd0cea3fd..392880d6c79d2e4cd770704874d58b937e23fcb8 100644 (file)
@@ -39,3 +39,7 @@ a
 real 0.00
 user 0.00
 sys 0.00
+real 0.00
+user 0.00
+sys 0.00
+4
index fa8febed370e35d882a06bf5d68d9b6e6e99b74d..3fe5f770be66f01142fad4018e7c2aa8710456ec 100644 (file)
@@ -54,3 +54,10 @@ echo $?
 echo $?
 
 time -p -- echo a
+
+time -- :
+
+# this should print timing information
+. ./test-glue-functions
+
+${THIS_SH} -c '{ time; echo after; }' |& wc -l | _cut_leading_spaces
index 303e685dc345bf3f4fc7801e979021a03386b121..bf9aba0dc523ad6b01fe061728384f477df7c5ba 100644 (file)
@@ -72,6 +72,8 @@ string \
 string \
 string \
 string \}
+escape\
+escape\
 'weferfds'\''dsfsdf' 
 'weferfdsdsfsdf'
 'weferfds'\''dsfsdf'
index 0a0b4afe4ceca243b2c248c402110db7454dc738..f454f8b08d62077502604d94842517c0f70f32d7 100644 (file)
@@ -133,6 +133,13 @@ echo ${foo:-'string \'}
 echo "${foo:-string \\}"
 echo ${foo:-string \\\}}
 
+: ${TMPDIR:=/tmp}
+
+${THIS_SH} -c 'echo escape\'
+printf 'echo escape\' > $TMPDIR/quote-$$
+${THIS_SH} $TMPDIR/quote-$$
+rm -f $TMPDIR/quote-$$
+
 ${THIS_SH} ./quote1.sub
 ${THIS_SH} ./quote2.sub
 ${THIS_SH} ./quote3.sub
index 8db1041422b8eec8acf48010bcc27009cc19c965..458befdd723ce8540879756baef39341719ae1fb 100644 (file)
@@ -3,7 +3,11 @@ abc
 abc
 def
 def
-./redir.tests: line 44: $z: ambiguous redirect
+ghi
+./redir.tests: line 49: -1: ambiguous redirect
+./redir.tests: line 50: exec: -1: invalid option
+exec: usage: exec [-cl] [-a name] [command [argument ...]] [redirection ...]
+./redir.tests: line 55: $z: ambiguous redirect
 Point 1
 Point 2
 to a
@@ -44,7 +48,7 @@ kl
 ab
 cd
 cd
-./redir.tests: line 170: redir1.*: No such file or directory
+./redir.tests: line 181: redir1.*: No such file or directory
 #   This program is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
 #   the Free Software Foundation, either version 3 of the License, or
index 63bd4d374cca0db010b8bfdc68520271dcd7d332..ca9eba9d0a3fd96f518661091e946479b00ba030 100644 (file)
@@ -24,20 +24,31 @@ cat /tmp/redir-test
 
 set -o noclobber
 
-#this should be an error
+#this should be an error, so it needs the same fixed filename
 echo def > /tmp/redir-test
 cat /tmp/redir-test
 
 # but this should succeed
-echo def > /tmp/redir-test-2
-cat /tmp/redir-test-2
+echo def > $TMPDIR/redir-test-2
+cat $TMPDIR/redir-test-2
 
 # and so should this
 echo def >| /tmp/redir-test
 cat /tmp/redir-test
 
+# this should work as normal
+echo ghi >| $TMPDIR/redir-test-3
+cat $TMPDIR/redir-test-3
+
 set +o noclobber
-rm /tmp/redir-test /tmp/redir-test-2
+rm -f /tmp/redir-test
+rm -f $TMPDIR/redir-test-2 $TMPDIR/redir-test-3
+
+# these are errors
+fd=-1
+exec <&$fd
+exec $fd</dev/null
+unset -v fd
 
 # this should be an error
 z="a b"
@@ -71,7 +82,7 @@ cat $TMPDIR/bash-c
 echo "Point 5"
 
 # clean up before running scripts
-exec 4>&- 5>&- 6<&-
+exec 4>&- 5>&- 6<&$unset-              # ksh93 quirk with unset variable
 
 rm -f $TMPDIR/bash-a $TMPDIR/bash-b $TMPDIR/bash-c
 
diff --git a/tests/run-invocation b/tests/run-invocation
new file mode 100644 (file)
index 0000000..5851b6c
--- /dev/null
@@ -0,0 +1,2 @@
+${THIS_SH} ./invocation.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT}
+diff ${BASH_TSTOUT} invocation.right && rm -f ${BASH_TSTOUT}
index e2a9f2c4b17ec258426d40bae4c9c1e449f2ffed..d5bce867d10474b17d75fd45c08859d61811667a 100644 (file)
@@ -22,6 +22,8 @@ until succeeded: 4
 if succeeded
 AND list succeeded
 OR list succeeded
+00 01 02 03 04 05 06 07 08 09 
+00 01 02 03 04 05 06 07 08 09 
 ! succeeded
 eval succeeded
 ! eval succeeded -- 1
index 3e0d66981d528ac262e1ef308d398406589a05f2..a0311be43fe0f5b140e59c3d66e9ae559eab55b9 100644 (file)
@@ -80,6 +80,19 @@ echo AND list succeeded
 
 false || echo OR list succeeded
 
+# more compound commands containing failing commands
+for (( f=0; f<10; f++ )); do
+       printf '%.2d ' $f
+       false
+done && echo done
+echo
+
+for f in {0..9}; do
+       printf '%.2d ' $f
+       false
+done && echo done
+echo
+
 ! false
 echo ! succeeded
 
index 18ce0ee02767e0c47f8dd669146f935b39e40a34..f47cfc02985a89176ca9b8077c207efe2c269ebc 100644 (file)
@@ -32,4 +32,7 @@ time ${THIS_SH} /dev/null
 printf "\ntimes:\n"
 times
 
+printf "\ntime standalone:\n"
+{ time ; echo after; } |& wc -l
+
 exit 0
index 4338ff4cb292f6140e2b325dd28cfad29a471457..58d868368940022af8a043b0816b6045e9a63cfd 100644 (file)
@@ -105,6 +105,12 @@ fn
 after 1
 fn
 after 2
+before
+after
+CHLD
+CHLD
+CHLD
+CHLD
 caught a child death
 caught a child death
 caught a child death
index 585fb41bc57513e45883d84f6076c50120dd5af9..902de24db1a069169348944ad12f65cab4e9366c 100644 (file)
@@ -93,6 +93,10 @@ ${THIS_SH} ./trap6.sub
 # eval and ERR trap
 ${THIS_SH} ./trap7.sub
 
+# SIGCHLD traps
+${THIS_SH} ./trap8.sub
+
+
 #
 # show that setting a trap on SIGCHLD is not disastrous.
 #
diff --git a/tests/trap8.sub b/tests/trap8.sub
new file mode 100644 (file)
index 0000000..6f719bb
--- /dev/null
@@ -0,0 +1,14 @@
+# tests for traps on SIGCHLD and async commands
+
+set -m
+
+trap 'echo CHLD' SIGCHLD
+
+{ echo before ; : ; echo after; } &
+wait
+
+sleep 1 &
+sleep 1 &
+
+sleep 1
+wait
index 6465595b58086b545c5ec3c6bbc9d3af0b9d5a51..f14fa5eff78c24424f7f53f87f69b7f20afe0f8e 100644 (file)
@@ -11,6 +11,8 @@ bar ()
 ./vredir.tests: line 19: v: readonly variable
 ./vredir.tests: line 19: v: cannot assign fd to variable
 42
+./vredir.tests: line 38: v: readonly variable
+./vredir.tests: line 38: v: cannot assign fd to variable
 bar is a function
 bar () 
 { 
@@ -98,4 +100,6 @@ swizzle ()
     exec {stdin}<&${fd[0]}-;
     exec {stdout}>&${fd[1]}-
 }
-./vredir8.sub: line 12: $fd: Bad file descriptor
+redir 2
+./vredir8.sub: line 33: $fd: Bad file descriptor
+./vredir8.sub: line 38: $fd: Bad file descriptor
index bd4cb77522cb730d8102f9f6d32ec1c52e0351e3..2a6cc18a3e9d60acd001e88d6fde722d5b3e4856 100644 (file)
@@ -32,8 +32,10 @@ rm -f $TMPFILE
 type bar
 exec {v}>&-
 
+# errors
 readonly v=42
 bar
+exec {v}>&1
 
 echo foo 1 2>&1 >&$v | { grep -q '\$v: Bad' || echo 'bad foo 1'; }
 echo foo 2 2>&1 >&$v | { grep -q '\$v: Bad' || echo 'bad foo 2'; }
index e87b45b3c26b3ad6d0a3e27e6ae108f09adaf74f..804626dc4545acc34b8f459382e9c6bcd76b2ce6 100644 (file)
@@ -1,13 +1,40 @@
+#   This program is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
 # test varredir_close
 
+# these should work fine
+
 : {fd}<>/dev/null
 
 echo redir 1 >&$fd
 exec {fd}>&-
 
+: {fd}>&1
+echo redir 2 >&$fd
+exec {fd}>&-
+
 shopt -s varredir_close
 
 : {fd}<>/dev/tty
 
-echo redir 2 >&$fd
+# these should fail with Bad file descriptor errors
+echo redir 3 >&$fd
 exec {fd}>&-
+unset fd
+
+: {fd}>&1
+echo redir 4 >&$fd
+unset fd
+