fix for parameter length expressions for nameref variables expanding to invalid identifiers

This commit is contained in:
Chet Ramey
2022-12-13 12:57:47 -05:00
parent 237c32ba16
commit 49918d90cd
12 changed files with 7022 additions and 5351 deletions
+11
View File
@@ -558,3 +558,14 @@ declare -ai a=([0]="0" [1]="16")
12
16
declare -ai a=([0]="0" [1]="16")
./nameref24.sub: line 24: declare: `': not a valid identifier
./nameref24.sub: line 25: declare: `a&b': invalid variable name for name reference
3
3
0
0
0
./nameref24.sub: line 38: declare: `aa&bb': invalid variable name for name reference
3
3
5
+42
View File
@@ -0,0 +1,42 @@
# 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/>.
#
# issues with taking the length of nameref variables
#
# just the basics
scalar=foo
declare -a array=(foo)
declare -n name=array
declare -n name1=array[0]
declare -n name2=unset
declare -n name3=
declare -n name4='a&b'
echo ${#name} # length of nameref resolving to set variable
echo ${#name1} # length of nameref resolving to valid non-identifier
echo ${#name2} # length of nameref resolving to unset variable
echo ${#name3} # length of nameref resolving to empty string
echo ${#name4} # length of nameref resolving to invalid non-identifier
unset -n name name1
declare -n name=scalar
declare -n name1=scalar[0]
name4='aa&bb'
declare -n name4
echo ${#name} # length of nameref resolving to set variable
echo ${#name1} # length of nameref resolving to valid non-identifier
echo ${#name4} # length of nameref resolving to invalid non-identifier