change to behavior of '&' in pattern substitution replacement string; fix for blank lines in multiline commands saved in command history

This commit is contained in:
Chet Ramey
2022-01-18 10:59:53 -05:00
parent 5e6f45d9b1
commit 2a1c81bf63
31 changed files with 1596 additions and 1312 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
BUILD_DIR=/usr/local/build/chet/bash/bash-current
BUILD_DIR=/usr/local/build/bash/bash-current
THIS_SH=$BUILD_DIR/bash
PATH=$PATH:$BUILD_DIR
+9 -4
View File
@@ -50,15 +50,20 @@ unset before after
# EPOCHSECONDS
# not exact, but should work
# could also use python -c 'import time; ts = int(time.time()); print(ts)'
now1=$(perl -e 'print time')
# date +%s should be portable enough now
# then try gawk, perl, python in that order
now1=$(date +%s 2>/dev/null) D=date
[ -z "$now1" ] && now1=$(gawk 'BEGIN { print systime(); }' 2>/dev/null) D=gawk
[ -z "$now1" ] && now1=$(perl -e 'print time' 2>/dev/null) D=perl
[ -z "$now1" ] && now1=$(python -c 'import time; ts = int(time.time()); print(ts)' 2>/dev/null) D=python
now2=$EPOCHSECONDS
case $now1 in
$now2) echo EPOCHSECONDS ok ;;
*) echo "current time via perl and EPOCHSECONDS possible mismatch|$now1|$now2" >&2 ;;
'') echo "cannot get current time using date/gawk/perl/python" >&2 ;;
*) echo "current time via $D and EPOCHSECONDS possible mismatch|$now1|$now2" >&2 ;;
esac
unset now1 now2
unset now1 now2 D
LC_ALL=C # force decimal point to `.'
now1=$EPOCHREALTIME
+1 -1
View File
@@ -4,7 +4,7 @@ exportfunc ok 2
./exportfunc.tests: eval: line 44: syntax error: unexpected end of file
./exportfunc.tests: line 43: cve7169-bad2: No such file or directory
./exportfunc1.sub: line 14: maximum here-document count exceeded
./exportfunc.tests: line 64: HELLO_WORLD: No such file or directory
./exportfunc.tests: line 72: HELLO_WORLD: No such file or directory
eval ok
./exportfunc3.sub: line 23: export: foo=bar: cannot export
status: 1
+9 -1
View File
@@ -50,10 +50,18 @@ ${THIS_SH} ./exportfunc1.sub
${THIS_SH} ./exportfunc2.sub
# CVE-2014-6277
A100=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
A1000=${A100}
for (( i = 0; i < 999; i++ ))
do
A1000+=${A100}
done
env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<0 0" ${THIS_SH} -c foo 2>/dev/null
env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<`perl -e '{print "A"x100000}'` 0" ${THIS_SH} -c foo 2>/dev/null
env BASH_FUNC_foo%%="() { 000(){>0;}&000(){ 0;}<<${A1000} 0" ${THIS_SH} -c foo 2>/dev/null
${THIS_SH} -c "f(){ x(){ _;}; x(){ _;}<<a;}" 2>/dev/null
unset A100 A1000
# CVE-2014-6278
+6
View File
@@ -11,6 +11,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# since we look at functions below, remove all functions now
funcs=$(compgen -A function)
if [ -n "$funcs" ]; then
unset -f $funcs
fi
a()
{
x=$((x - 1))
+8
View File
@@ -13,6 +13,14 @@
#
. ./test-glue-functions
# this locale causes problems all over the place
if locale -a | grep -i '^zh_HK\.big5hkscs' >/dev/null ; then
:
else
echo "glob2.sub: warning: you do not have the zh_HK.big5hkscs locale installed;" >&2
echo "glob2.sub: warning: that will cause some of these tests to fail." >&2
fi
var='ab\'
case $var in
+2
View File
@@ -11,6 +11,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
[ $UID -eq 0 ] && { echo "glob5.sub: the test suite should not be run as root" >&2 ; }
ORIGD=$PWD
: ${TMPDIR:=/var/tmp}
+1
View File
@@ -12,6 +12,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# tests of the backslash-in-glob-patterns discussion on the austin-group ML
[ $UID -eq 0 ] && { echo "glob6.sub: the test suite should not be run as root" >&2 ; }
: ${TMPDIR:=/var/tmp}
+6
View File
@@ -11,6 +11,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# since we look at functions below, remove all functions now
funcs=$(compgen -A function)
if [ -n "$funcs" ]; then
unset -f $funcs
fi
# basics
read x <<<"alpha"
echo "$x"
+21 -1
View File
@@ -1,5 +1,25 @@
# 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 locale causes problems all over the place
unset LC_ALL LC_NUMERIC
export LANG=de_DE.UTF-8
if locale -a | grep -i '^de_DE\.UTF.*8' >/dev/null ; then
export LANG=de_DE.UTF-8
else
echo "intl2.sub: warning: you do not have the de_DE.UTF-8 locale installed;" >&2
echo "intl2.sub: that will cause some of these tests to fail." >&2
fi
printf '%.4f\n' 1
LANG=C printf '%.4f\n' 1
+2
View File
@@ -34,4 +34,6 @@ wait
# the sleep is intended to give the kill time to execute before the job
# exits
(sleep 1 ; cat ) &
# suppress any message about terminated process
exec 2>/dev/null
kill -1 %% && echo i killed it || echo could not kill it
+2
View File
@@ -3,4 +3,6 @@ set -m
sleep 20 &
echo $(jobs)
echo $(fg %% ; jobs)
# suppress any message about sleep 20 being terminated
exec 2>/dev/null
kill %1
+27 -6
View File
@@ -735,30 +735,51 @@ a
defg
defg
defg
$'&' $'&' $'&' $'&' $'&' $'&' $'&'
$'a' $'b' $'c' $'d' $'e' $'f' $'g'
a b c d e f g
a b c d e f g
a b c d e f g
& & & & & & &
& & & & & & &
& & & & & & &
\& \& \& \& \& \& \&
a a a a a a a
3 3 3 3 3 3 3
abc defg
abc defg
abc defg
abc defg
abc defg
& defg
& defg
& defg
\& defg
\abc defg
abcdefg
abcdefg
&defg
&defg
\abcdefg
\&defg
\&defg
\abcdefg
\\&defg
&defg
&defg
\&defg
\&defg
\\&defg
letx&yee
letx&yee
letxssyee
letxssyee
letx\&yee
letx\&yee
letx&yee
letx&yee
let\&ee
let\\ssee
let\ssee
let\ssee
let\&ee
let\&ee
let&ee
let&ee
argv[1] = </>
argv[1] = </>
+40
View File
@@ -16,6 +16,8 @@ HOME=/homes/chet
string=abcdefg
set -- a b c
shopt -u patsub_replacement
# verify existing behavior
echo ${string/abc/~}
echo "${string/abc/~}"
@@ -29,6 +31,11 @@ echo ${string//?/\$\'&\' }
shopt -s patsub_replacement
echo ${string//?/\$\'&\' }
echo ${string//?/& }
echo "${string//?/& }"
echo ${string//?/\& }
echo "${string//?/\& }"
echo ${string//?/"& "}
@@ -51,7 +58,9 @@ rep='\\&'
echo "${string/abc/&}"
echo ${string/abc/\&}
echo "${string/abc/\\&}"
echo ${string/abc/"\\&"}
echo "${string/abc/"\\&"}"
echo ${string/abc/$rep}
echo ${string/abc/"$rep"}
shopt -u patsub_replacement
@@ -61,3 +70,34 @@ echo ${string/abc/\&}
echo "${string/abc/\\&}"
echo "${string/abc/"\\&"}"
echo ${string/abc/"$rep"}
shopt -s patsub_replacement
repl='x&y'
r2='x\&y'
var='letssee'
pat=ss
echo ${var//$pat/"$repl"}
echo "${var//$pat/"$repl"}"
echo ${var//$pat/$repl}
echo "${var//$pat/$repl}"
echo ${var//$pat/"$r2"}
echo "${var//$pat/"$r2"}"
echo ${var//$pat/$r2}
echo "${var//$pat/$r2}"
r2='\\&'
r3='\&'
echo ${var//$pat/\\\&}
echo ${var//$pat/\\$r2}
echo ${var//$pat/\\&}
echo ${var//$pat/$r2}
echo ${var//$pat/"\&"}
echo ${var//$pat/"$r3"}
echo ${var//$pat/"&"}
echo ${var//$pat/$r3}
+3 -3
View File
@@ -69,11 +69,11 @@ FOO
0
0
1
[?2004h[?2004l
timeout 1: ok
unset or null 1
unset or null 1
timeout 2: ok
unset or null 2
timeout 2: ok
timeout 3: ok
unset or null 3
timeout 4: ok
abcde
+3
View File
@@ -13,6 +13,9 @@
#
# test behavior of native readline timeouts
# turn off bracketed paste to avoid spurious output
bind 'set enable-bracketed-paste off' 2>/dev/null
read -t 0.00001 -e var
estat=$?
if [ $estat -gt 128 ]; then
-3
View File
@@ -1,8 +1,5 @@
# See whether or not we can use `diff -a'
( diff -a ./intl.right ./intl.right >/dev/null 2>&1 ) && AFLAG=-a
echo "warning: some of these tests will fail if you do not have UTF-8" >&2
echo "warning: locales installed on your system." >&2
${THIS_SH} ./intl.tests > ${BASH_TSTOUT}
diff $AFLAG ${BASH_TSTOUT} intl.right && rm -f ${BASH_TSTOUT}
+8 -1
View File
@@ -109,7 +109,14 @@ fr_FR_ISO_8859_1=(
[0x00fb]=$'\373' [0x00fc]=$'\374' [0x00fd]=$'\375' [0x00fe]=$'\376'
)
TestCodePage fr_FR.ISO8859-1 fr_FR_ISO_8859_1
# this locale causes problems all over the place
if locale -a | grep -i '^fr_FR\.ISO8859.*1' >/dev/null ; then
TestCodePage fr_FR.ISO8859-1 fr_FR_ISO_8859_1
else
echo "unicode1.sub: warning: you do not have the fr_FR.ISO8859-1 locale installed;" >&2
echo "unicode1.sub: that will cause some of these tests to fail." >&2
fi
zh_TW_BIG5=(
[0x00f6]=$'\366' [0x00f7]=$'\367' [0x00f8]=$'\370' [0x00f9]=$'\371' [0x00fa]=$'\372'