mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-08-02 08:18:14 +02:00
enable support for using `&' in the pattern substitution replacement string
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ a
|
||||
[27] aaa
|
||||
[28] aaa
|
||||
[29] aaa
|
||||
declare -a array=([0]="a" [1]="b" [2]="c" [3]=$'\n')
|
||||
1 2 3 4 5
|
||||
foo 0 1
|
||||
|
||||
|
||||
+6
-1
@@ -52,6 +52,11 @@ for (( i = 0 ; i < ${#E[@]} ; i++ )); do
|
||||
echo "${E[${i}]}"
|
||||
done
|
||||
|
||||
${THIS_SH} ./mapfile1.sub
|
||||
unset -v s array
|
||||
s=$'a\xffb\xffc\xff'
|
||||
mapfile -t -d $'\xff' array <<<"$s"
|
||||
declare -p array
|
||||
unset -v s array
|
||||
|
||||
${THIS_SH} ./mapfile1.sub
|
||||
${THIS_SH} ./mapfile2.sub
|
||||
|
||||
+21
-1
@@ -617,7 +617,7 @@ c Sub = 0 2 4 8
|
||||
<>
|
||||
<>
|
||||
<'ab '\''cd'\'' ef'>
|
||||
./new-exp10.sub: line 24: ${x@C}: bad substitution
|
||||
bash: line 1: ${x@C}: bad substitution
|
||||
<'ab'> <'cd ef'> <''> <'gh'>
|
||||
<'ab' 'cd ef' '' 'gh'>
|
||||
<'ab'> <'cd> <ef'> <''> <'gh'>
|
||||
@@ -729,6 +729,26 @@ a
|
||||
a
|
||||
a
|
||||
a
|
||||
/homes/chetdefg
|
||||
/homes/chetdefg
|
||||
~defg
|
||||
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
|
||||
argv[1] = </>
|
||||
argv[1] = </>
|
||||
|
||||
|
||||
@@ -631,6 +631,10 @@ ${THIS_SH} ./new-exp14.sub
|
||||
# ongoing work with a/A parameter transformations and `nounset'
|
||||
${THIS_SH} ./new-exp15.sub
|
||||
|
||||
# pattern substitution with `&' (quoted and unquoted) in the replacement string
|
||||
${THIS_SH} ./new-exp16.sub
|
||||
|
||||
|
||||
# problems with stray CTLNUL in bash-4.0-alpha
|
||||
unset a
|
||||
a=/a
|
||||
|
||||
+3
-1
@@ -21,7 +21,9 @@ printf "<%s>" "${x@A}" ; echo
|
||||
x="ab 'cd' ef"
|
||||
printf "<%s> " "${x@Q}" ; echo
|
||||
|
||||
printf "<%s>" "${x@C}"
|
||||
# this needs to be run in a subshell because invalid transformation operators
|
||||
# are now treated as substitution errors, fatal in non-interactive shells
|
||||
${THIS_SH} -c 'x=abcdef ; printf "<%s>" "${x@C}"' bash
|
||||
|
||||
# if unquoted, normal word splitting happens
|
||||
set -- ab 'cd ef' '' gh
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
HOME=/homes/chet
|
||||
string=abcdefg
|
||||
set -- a b c
|
||||
|
||||
# verify existing behavior
|
||||
echo ${string/abc/~}
|
||||
echo "${string/abc/~}"
|
||||
echo ${string/abc/"~"}
|
||||
|
||||
echo ${string/abc/$notthere}
|
||||
echo "${string/abc/$notthere}"
|
||||
echo "${string/abc/"$notthere"}"
|
||||
|
||||
echo ${string//?/\$\'&\' }
|
||||
|
||||
echo ${string//?/\& }
|
||||
echo "${string//?/\& }"
|
||||
echo ${string//?/"& "}
|
||||
echo ${string//?/"\& "}
|
||||
|
||||
echo "${string//?/"a "}"
|
||||
echo "${string//?/"$# "}"
|
||||
|
||||
echo ${string/abc/& }
|
||||
echo "${string/abc/& }"
|
||||
echo ${string/abc/"& "}
|
||||
|
||||
echo ${string/abc/\& }
|
||||
echo "${string/abc/\& }"
|
||||
echo ${string/abc/"\& "}
|
||||
echo ${string/abc/\\& }
|
||||
Reference in New Issue
Block a user