From 6c20c8ed2cb9ab69a1a57ccb2b9b79969a808321 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 17:38:56 +0200 Subject: Adding upstream version 5.2.15. Signed-off-by: Daniel Baumann --- tests/quotearray1.sub | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 tests/quotearray1.sub (limited to 'tests/quotearray1.sub') diff --git a/tests/quotearray1.sub b/tests/quotearray1.sub new file mode 100644 index 0000000..19741b1 --- /dev/null +++ b/tests/quotearray1.sub @@ -0,0 +1,131 @@ +# 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 . +# + +# arithmetic operators for conditional commands and arithmetic commands + +declare -A assoc +declare -a index + +key='x],b[$(echo uname >&2)' +key1=']' +key2='` echo >&2 foo`' +key3='~' +key4='7<(4+2)' +key5='$( echo 2>& date)' +key6='$(echo foo)' + +[[ -n assoc[$key] ]] +declare -p assoc + +assoc[$key]=42 +assoc[$key1]=12 +assoc[$key2]=128 +assoc[$key3]=42 +assoc[0]=0 + +[[ assoc[$key] -eq assoc[$key] ]] +echo $? + +[[ assoc[$key] -gt assoc[$key1] ]] +echo $? + +[[ assoc[$key2] -lt assoc[$key] ]] +echo $? + +[[ assoc[$key] -eq assoc[$key3] ]] +echo $? + +[[ index[7<(4+2)] -le assoc[0] ]] +echo $? +[[ index[$key4] -le assoc[0] ]] +echo $? + +assoc[$key5]=foo +declare -p assoc + +echo "${assoc[$key5]}" + +[[ -v assoc[$key5] ]] +echo $? +[[ -v assoc[$key] ]] +echo $? + +unset assoc + +declare -a array +index='0],b[1'; +((array[$index]++)) + +declare -p array + +unset array + +declare -A assoc + +assoc[$key]=42 +assoc[$key4]=42 + +[[ -v assoc[$key] ]] +echo $? +[[ -v assoc["$key"] ]] +echo $? + +[[ -v assoc[$key4] ]] +echo $? +[[ -v assoc["$key4"] ]] +echo $? + +[[ -v assoc['$key'] ]] +echo $? +[[ -v assoc['$key4'] ]] +echo $? + +unset -v assoc + +declare -A aa +aa[$key5]=foo + +declare -p aa +echo "${aa[$key5]}" + +[[ -v aa[$key5] ]] +echo $? + +[[ -v aa[$key] ]] +echo $? + +aa[$key6]=42 +# this still performs expansion +test -v aa["$key6"] +echo $? +# should be an error +test -v aa[$key6] +echo $? + +unset aa key + +declare -A assoc + +mytest () +{ + assoc["$1"]=123 + [[ -v assoc["$1"] ]] + printf '[[ -v assoc[%s] ]]; $?=%s\n' "$1" "$?" +} + +mytest 'a' +mytest '"' +declare -p assoc +unset -v assoc +unset -f mytest -- cgit v1.2.3