fix for potential read builtin crash if bash gets a signal before read reads any input; make wait -f work if there are no pid or job arguments and update documentation; save and restore variable reflected in $BASH_COMMAND around shell function calls

This commit is contained in:
Chet Ramey
2025-09-18 17:54:55 -04:00
parent 013fae2c98
commit cf8a2518c8
15 changed files with 136 additions and 28 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ bash: -c: line 1: unexpected argument `<' to conditional unary operator
bash: -c: line 1: syntax error near `<'
bash: -c: line 1: `[[ -n < ]]'
ERR: 22: -[[ -n $unset ]]- failed
ERR: 28: -[[ -z nonempty ]]- failed
ERR: 28: -func- failed
+ [[ -t X ]]
./cond-xtrace1.sub: line 6: [[: X: integer expected
+ [[ '' > 7 ]]
+8 -3
View File
@@ -120,15 +120,20 @@ exit=0
A
In trap-argument: last command preceding the trap action
In a function call: last command in the trap action
ERR: 23: -func- failed
ERR: 20: -[[ -z nonempty ]]- failed
ERR: 27: -func- failed
ERR: 35: -func2- failed
ERR: 39: -func2- failed
caught a child death
caught a child death
caught a child death
trap -- 'echo caught a child death' SIGCHLD
echo caught a child death
./trap.tests: line 118: trap: cannot specify both -p and -P
./trap.tests: line 119: trap: -P requires at least one signal name
./trap.tests: line 121: trap: cannot specify both -p and -P
./trap.tests: line 122: trap: -P requires at least one signal name
trap: usage: trap [-Plp] [[action] signal_spec ...]
./trap.tests: line 121: trap: -x: invalid option
./trap.tests: line 124: trap: -x: invalid option
trap: usage: trap [-Plp] [[action] signal_spec ...]
trap -- 'echo exiting' EXIT
trap -- 'echo aborting' SIGABRT
+3
View File
@@ -99,6 +99,9 @@ ${THIS_SH} ./trap8.sub
# return without argument in trap string
${THIS_SH} ./trap9.sub
# ERR trap and functions
${THIS_SH} ./trap10.sub
#
# show that setting a trap on SIGCHLD is not disastrous.
#
+40
View File
@@ -0,0 +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/>.
#
trap 'echo ERR: $LINENO: -$BASH_COMMAND- failed' ERR
# the conditional command will fail, then func will fail
func()
{
[[ -z nonempty ]]
}
# func will fail
func
set -E
# the conditional command will fail, then func will fail
func
set +E
func2()
{
return 1
}
# func2 will fail
func2
# if we change so that `return 1' triffers the ERR trap, this will change
set -E
func2
set +E
+2 -7
View File
@@ -50,13 +50,8 @@ exit 42 | command false
command command command false
unset FALSE
if [ -x /bin/false ]; then
FALSE=/bin/false
elif [ -x /usr/bin/false ]; then
FALSE=/usr/bin/false
elif [ -x /usr/local/bin/false ]; then
FALSE=/usr/local/bin/false
else
FALSE=$(type -P false)
if [ -z "$FALSE" ]; then
FALSE='command false'
fi