fix tilde expansion in associative array compound assignments

This commit is contained in:
Chet Ramey
2023-02-07 10:16:51 -05:00
parent 315095ad7f
commit 7411382644
10 changed files with 144 additions and 11 deletions
+6
View File
@@ -787,3 +787,9 @@ FOO
declare -Au A=([Darwin]="FOO" )
FOO
declare -Au A=(["@"]="FOO" )
declare -a aa=([0]="/homes/cj/Desktop")
declare -a aa=([0]="/homes/cj/Desktop")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
declare -a aa=([0]="/homes/cj/Desktop:/homes/cj/Library:/homes/cj/Documents" [1]="/homes/cj/Applications")
+1
View File
@@ -427,3 +427,4 @@ ${THIS_SH} ./array27.sub
${THIS_SH} ./array28.sub
${THIS_SH} ./array29.sub
${THIS_SH} ./array30.sub
${THIS_SH} ./array31.sub
+43
View File
@@ -0,0 +1,43 @@
# 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/>.
#
# Tilde expansion in indexed array assignments; prep for future work
HOME=/homes/cj
declare -a aa
aa=([0]=~/Desktop)
declare -p aa
unset aa
declare -a aa=([0]=~/Desktop)
declare -p aa
unset aa
declare -a aa=([0]=~/Desktop:~/Library:~/Documents)
declare -p aa
unset aa
declare -a aa
aa=([0]=~/Desktop:~/Library:~/Documents)
declare -p aa
unset aa
declare -a aa=([0]=~/Desktop:~/Library:~/Documents [1]=~/Applications)
declare -p aa
unset aa
declare -a aa
aa=([0]=~/Desktop:~/Library:~/Documents [1]=~/Applications)
declare -p aa
unset aa
+7
View File
@@ -398,3 +398,10 @@ declare -A A=()
declare -A A=(["]"]="rbracket" ["["]="lbracket" )
declare -A A=()
5: ok 1
declare -A aa=([key]="/homes/cj/Desktop" )
declare -A aa=([key]="/homes/cj/Desktop" )
declare -A aa=([k2]="/homes/cj/Library" [key]="/homes/cj/Desktop" )
declare -A aa=([/homes/cj/key]="/homes/cj/Desktop" )
declare -A aa=([/homes/cj/Documents]="/homes/cj/Library" [/homes/cj/key]="/homes/cj/Desktop" )
declare -A aa=([/homes/cj/Documents]="/homes/cj/Library" [/homes/cj/key]="/homes/cj/Desktop:/homes/cj/Documents:/homes/cj/Applications" )
declare -A aa=([/homes/cj/Documents]="/homes/cj/Library" [/homes/cj/key]="/homes/cj/Desktop:/homes/cj/Documents:/homes/cj/Applications" )
+2
View File
@@ -266,3 +266,5 @@ ${THIS_SH} ./assoc17.sub
# tests with `[' and `]' subscripts and printf/read/wait builtins
${THIS_SH} ./assoc18.sub
# tests with tilde expansion in keys and values post-bash-5.2
${THIS_SH} ./assoc19.sub
+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/>.
#
# Problems with tilde expansion of keys and values in bash-5.2
HOME=/homes/cj
declare -A aa=([key]=~/Desktop)
declare -p aa
unset aa
declare -A aa
aa=([key]=~/Desktop)
declare -p aa
unset aa
declare -A aa=([key]=~/Desktop [k2]=~/Library )
declare -p aa
unset aa
declare -A aa=([~/key]=~/Desktop)
declare -p aa
unset aa
declare -A aa
aa=([~/key]=~/Desktop)
aa[~/Documents]=~/Library
declare -p aa
unset aa
declare -A aa
aa=([~/key]=~/Desktop:~/Documents:~/Applications)
aa[~/Documents]=~/Library
declare -p aa
unset aa
declare -A aa=([~/key]=~/Desktop:~/Documents:~/Applications [~/Documents]=~/Library)
declare -p aa