From: Chet Ramey Date: Mon, 25 Sep 2023 19:08:04 +0000 (-0400) Subject: a select command invalid selection variable name is now a fatal error in posix mode... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b3958b3ab44054a42f16bbc9ff9bc162eaf783b1;p=thirdparty%2Fbash.git a select command invalid selection variable name is now a fatal error in posix mode; many test suite additions --- diff --git a/CWRU/CWRU.chlog b/CWRU/CWRU.chlog index 88ddf9c94..e34b41799 100644 --- a/CWRU/CWRU.chlog +++ b/CWRU/CWRU.chlog @@ -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 + +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 + diff --git a/MANIFEST b/MANIFEST index 148b61721..85b004038 100644 --- 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 diff --git a/builtins/bind.def b/builtins/bind.def index 3cf901541..e52e1cb06 100644 --- a/builtins/bind.def +++ b/builtins/bind.def @@ -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); diff --git a/builtins/command.def b/builtins/command.def index b5f0e188b..4f980592a 100644 --- a/builtins/command.def +++ b/builtins/command.def @@ -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); } diff --git a/builtins/getopts.def b/builtins/getopts.def index b8cbc6545..3365ce1df 100644 --- a/builtins/getopts.def +++ b/builtins/getopts.def @@ -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); diff --git a/doc/bashref.texi b/doc/bashref.texi index dd143de39..156247ed4 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -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} diff --git a/execute_cmd.c b/execute_cmd.c index d54fa7f0a..73723db53 100644 --- a/execute_cmd.c +++ b/execute_cmd.c @@ -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; diff --git a/pcomplete.c b/pcomplete.c index e6c216004..aa6a0440b 100644 --- a/pcomplete.c +++ b/pcomplete.c @@ -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 267a9fc8b..ee66f5cb0 100644 --- 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) diff --git a/tests/alias.right b/tests/alias.right index 7b883c7d8..d5c53f41c 100644 --- a/tests/alias.right +++ b/tests/alias.right @@ -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") diff --git a/tests/alias.tests b/tests/alias.tests index c3a66f102..14d3c63f4 100644 --- a/tests/alias.tests +++ b/tests/alias.tests @@ -40,6 +40,8 @@ qfoo unalias qfoo qbar qbaz quux unalias -a +# error +unalias foo alias foo='echo ' alias bar=baz diff --git a/tests/arith.right b/tests/arith.right index 75c120013..e17a127a0 100644 --- a/tests/arith.right +++ b/tests/arith.right @@ -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 @@ -80,16 +83,18 @@ 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") diff --git a/tests/arith.tests b/tests/arith.tests index e9ab57651..fec2afd02 100644 --- a/tests/arith.tests +++ b/tests/arith.tests @@ -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 index 000000000..811139ed4 --- /dev/null +++ b/tests/arith9.sub @@ -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 diff --git a/tests/array.right b/tests/array.right index 1889facb2..b16870dc6 100644 --- a/tests/array.right +++ b/tests/array.right @@ -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 diff --git a/tests/array16.sub b/tests/array16.sub index b82dbca28..94013ea2f 100644 --- a/tests/array16.sub +++ b/tests/array16.sub @@ -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 $? diff --git a/tests/braces.right b/tests/braces.right index 401754647..75be33e81 100644 --- a/tests/braces.right +++ b/tests/braces.right @@ -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 diff --git a/tests/braces.tests b/tests/braces.tests index da0b624bc..56a08166a 100644 --- a/tests/braces.tests +++ b/tests/braces.tests @@ -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} diff --git a/tests/builtins.right b/tests/builtins.right index 58d3b99cc..e0b11ac4c 100644 --- a/tests/builtins.right +++ b/tests/builtins.right @@ -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 diff --git a/tests/builtins.tests b/tests/builtins.tests index 50fdbaba4..a09248692 100644 --- a/tests/builtins.tests +++ b/tests/builtins.tests @@ -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 diff --git a/tests/builtins8.sub b/tests/builtins8.sub index 1c1b133fe..8b049c09a 100644 --- a/tests/builtins8.sub +++ b/tests/builtins8.sub @@ -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 . +# + 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 index 000000000..d8f6c97c0 --- /dev/null +++ b/tests/builtins9.sub @@ -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 . +# + +# 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 found + +hash -r +hash -p / root diff --git a/tests/comsub-eof.right b/tests/comsub-eof.right index cd5ab6923..c6a4c9ef4 100644 --- a/tests/comsub-eof.right +++ b/tests/comsub-eof.right @@ -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') diff --git a/tests/comsub-eof0.sub b/tests/comsub-eof0.sub index 7490faabc..1cbbb819a 100644 --- a/tests/comsub-eof0.sub +++ b/tests/comsub-eof0.sub @@ -1,3 +1,9 @@ +# this works as it should, but with a warning +foo=$(cat < argv[1] = argv[1] = nested +blank ---- +blank ---- +blank ---- +blank ---- #esac a ok 1 diff --git a/tests/comsub.tests b/tests/comsub.tests index 8b89ce44d..5969f6ca6 100644 --- a/tests/comsub.tests +++ b/tests/comsub.tests @@ -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 index 000000000..f04f775cc --- /dev/null +++ b/tests/cond-error1.sub @@ -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 index 000000000..e7bf6859e --- /dev/null +++ b/tests/cond-xtrace1.sub @@ -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 ]] diff --git a/tests/cond.right b/tests/cond.right index 1b0e8c743..cbe552b2a 100644 --- a/tests/cond.right +++ b/tests/cond.right @@ -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 ]] diff --git a/tests/cond.tests b/tests/cond.tests index 020be32b2..68f168649 100644 --- a/tests/cond.tests +++ b/tests/cond.tests @@ -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 diff --git a/tests/errors.right b/tests/errors.right index 2df2c7e74..a95d00807 100644 --- a/tests/errors.right +++ b/tests/errors.right @@ -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 diff --git a/tests/errors.tests b/tests/errors.tests index 8161383f0..17354dc91 100644 --- a/tests/errors.tests +++ b/tests/errors.tests @@ -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 diff --git a/tests/errors4.sub b/tests/errors4.sub index 6b4050245..5ee6d583d 100644 --- a/tests/errors4.sub +++ b/tests/errors4.sub @@ -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 diff --git a/tests/glob.right b/tests/glob.right index 723ee7b46..4d89de806 100644 --- a/tests/glob.right +++ b/tests/glob.right @@ -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] = argv[2] = argv[3] = @@ -139,7 +155,7 @@ argv[2] = argv[3] = argv[4] = 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] = argv[1] = <*> argv[1] = diff --git a/tests/glob.tests b/tests/glob.tests index 02d530261..bdb2b774c 100644 --- a/tests/glob.tests +++ b/tests/glob.tests @@ -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 index 000000000..ff50efa40 --- /dev/null +++ b/tests/glob11.sub @@ -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 . +# + +# 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 diff --git a/tests/heredoc.right b/tests/heredoc.right index 634021388..d5a4a7d75 100644 --- a/tests/heredoc.right +++ b/tests/heredoc.right @@ -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 +'' diff --git a/tests/heredoc.tests b/tests/heredoc.tests index d3da798dd..2f94d1d72 100644 --- a/tests/heredoc.tests +++ b/tests/heredoc.tests @@ -80,6 +80,12 @@ F EOF true +# but unquoted here-documents remove backslash-newline +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 <. +# + +: ${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 < $TMPDIR/quote-$$ +${THIS_SH} $TMPDIR/quote-$$ +rm -f $TMPDIR/quote-$$ + ${THIS_SH} ./quote1.sub ${THIS_SH} ./quote2.sub ${THIS_SH} ./quote3.sub diff --git a/tests/redir.right b/tests/redir.right index 8db104142..458befdd7 100644 --- a/tests/redir.right +++ b/tests/redir.right @@ -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 diff --git a/tests/redir.tests b/tests/redir.tests index 63bd4d374..ca9eba9d0 100644 --- a/tests/redir.tests +++ b/tests/redir.tests @@ -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&- 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 index 000000000..5851b6cad --- /dev/null +++ b/tests/run-invocation @@ -0,0 +1,2 @@ +${THIS_SH} ./invocation.tests 2>&1 | grep -v '^expect' > ${BASH_TSTOUT} +diff ${BASH_TSTOUT} invocation.right && rm -f ${BASH_TSTOUT} diff --git a/tests/set-e.right b/tests/set-e.right index e2a9f2c4b..d5bce867d 100644 --- a/tests/set-e.right +++ b/tests/set-e.right @@ -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 diff --git a/tests/set-e.tests b/tests/set-e.tests index 3e0d66981..a0311be43 100644 --- a/tests/set-e.tests +++ b/tests/set-e.tests @@ -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 diff --git a/tests/time.tests b/tests/time.tests index 18ce0ee02..f47cfc029 100644 --- a/tests/time.tests +++ b/tests/time.tests @@ -32,4 +32,7 @@ time ${THIS_SH} /dev/null printf "\ntimes:\n" times +printf "\ntime standalone:\n" +{ time ; echo after; } |& wc -l + exit 0 diff --git a/tests/trap.right b/tests/trap.right index 4338ff4cb..58d868368 100644 --- a/tests/trap.right +++ b/tests/trap.right @@ -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 diff --git a/tests/trap.tests b/tests/trap.tests index 585fb41bc..902de24db 100644 --- a/tests/trap.tests +++ b/tests/trap.tests @@ -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 index 000000000..6f719bbfe --- /dev/null +++ b/tests/trap8.sub @@ -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 diff --git a/tests/vredir.right b/tests/vredir.right index 6465595b5..f14fa5eff 100644 --- a/tests/vredir.right +++ b/tests/vredir.right @@ -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 diff --git a/tests/vredir.tests b/tests/vredir.tests index bd4cb7752..2a6cc18a3 100644 --- a/tests/vredir.tests +++ b/tests/vredir.tests @@ -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'; } diff --git a/tests/vredir8.sub b/tests/vredir8.sub index e87b45b3c..804626dc4 100644 --- a/tests/vredir8.sub +++ b/tests/vredir8.sub @@ -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 . +# + # 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 +