process $'...' and $"..." in here-documents

This commit is contained in:
Chet Ramey
2021-03-15 09:30:44 -04:00
parent 2fe2e8197e
commit 83c4ad27c7
13 changed files with 242 additions and 13 deletions
+21 -1
View File
@@ -100,7 +100,27 @@ argv[2] = <threefour>
argv[1] = <two>
argv[2] = <threefi>
argv[3] = <ve>
1: OK
2: OK
3: OK
4: OK
5: OK
6: OK
7: OK
1: OK
2: OK
3: OK
4: OK
5: OK
5: OK
1: ${x#$'no\t'}
2: O${x#$'no\t'O}
3: ${x#n$'o\t'}
4: ${x#'no '}
5: ${x#$pat}
6: ${y#$'not'}
7: ${y#'not'}
comsub here-string
./heredoc.tests: line 149: warning: here-document at line 147 delimited by end-of-file (wanted `EOF')
./heredoc.tests: line 152: warning: here-document at line 150 delimited by end-of-file (wanted `EOF')
hi
there
+3
View File
@@ -137,6 +137,9 @@ ${THIS_SH} ./heredoc4.sub
# heredoc tests that use different size documents to test pipe implementation
${THIS_SH} ./heredoc5.sub
# test $'...' and $"..." quoted strings in here-documents
${THIS_SH} ./heredoc6.sub
echo $(
cat <<< "comsub here-string"
)
+50
View File
@@ -0,0 +1,50 @@
# 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 $'...' and $"..." strings in here documents (problem through bash-5.1)
pat=$'no\t'
x=$'no\tOK'
y=notOK
cat <<EOF
1: ${x#$'no\t'}
2: O${x#$'no\t'O}
3: ${x#n$'o\t'}
4: ${x#'no '}
5: ${x#$pat}
6: ${y#$'not'}
7: ${y#'not'}
EOF
cat <<EOF
1: ${x#$"no "}
2: ${x#n$"o "}
3: O${x#n$"o "O}
4: ${x#"no "}
5: ${y#$"not"}
5: ${y#"not"}
EOF
# we don't perform dollar-quote expansion if the here-doc delimiter is quoted
cat <<\EOF
1: ${x#$'no\t'}
2: O${x#$'no\t'O}
3: ${x#n$'o\t'}
4: ${x#'no '}
5: ${x#$pat}
6: ${y#$'not'}
7: ${y#'not'}
EOF
+2
View File
@@ -35,6 +35,8 @@ argv[1] = <hello, $world>
;foo
argv[1] = <^I>
argv[1] = <'A^IB'>
argv[1] = <a^Ib^Ic>
argv[1] = <$'a\tb\tc'>
hello' world
hello world!
hello' world!
+4
View File
@@ -128,6 +128,10 @@ unset mytab
recho "${mytab:-$'\t'}"
recho "$( args $'A\tB' )"
# tests for $'...' not being expanded when inside double quotes
recho $'a\tb\tc'
recho "$'a\tb\tc'"
${THIS_SH} ./nquote1.sub
${THIS_SH} ./nquote2.sub
${THIS_SH} ./nquote3.sub
+3 -2
View File
@@ -275,10 +275,11 @@ argv[2] = <b>
[ abc def ghi jkl / abc def ghi jkl ]
[ abc def ghi jkl ]
[ abc def ghi jkl / abc def ghi jkl / abc def ghi jkl ]
5: notOK
5: OK
OK
OK
5: $'not\ttoo\nbad'
5: 'not too
bad'
"A"
A
argv[1] = <"A">