diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 18:33:23 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 18:33:23 +0000 |
commit | 1d5cace9db9aef76f26b2d7ba54bbb76443b00b2 (patch) | |
tree | 314a15dd1aa103da13bdc83ba1d2105a290bc5ba /tests/array17.sub | |
parent | Initial commit. (diff) | |
download | bash-89791e9f494bebe33a9c52292a98f4f079926078.tar.xz bash-89791e9f494bebe33a9c52292a98f4f079926078.zip |
Adding upstream version 5.0.upstream/5.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/array17.sub')
-rw-r--r-- | tests/array17.sub | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/array17.sub b/tests/array17.sub new file mode 100644 index 0000000..302dc03 --- /dev/null +++ b/tests/array17.sub @@ -0,0 +1,78 @@ +# this shows the expansions an array subscript undergoes before being run +# through the arithmetic evaluator + +b=(0 1 2 3) + +# array subscripts undergo variable expansion +a=2 +echo ${b[$a]} + +# array subscripts undergo command substitution +echo ${b[$(echo 2)]} + +c='1+1' +d='1-+1' + +# array subscripts are expanded and the expanded value is treated as an +# expression +echo ${b[$c]} +echo ${b[c]} + +echo ${b[$d]} +echo ${b[d]} + +# array subscripts undergo parameter expansion +set -- 1 2 3 +echo ${b[$1]} + +# array subscripts undergo tilde expansion +HOME=2 +echo ${b[~]} + +# array subscripts undergo word splitting -- bug in bash versions through 4.3 + +x='b[$d]' +IFS=- +echo $((x)) +IFS=$' \t\n' + +set -- 1 + 2 + +x='d' +IFS=- +echo $((x)) +IFS=$' \t\n' + +# start of quoting tests; make sure that subscript is treated as double +# quoted (inhibits word splitting) but that double quotes are silently +# discarded through quote removal + +echo $(( $@ )) +echo "$(( $@ ))" + +echo $(( "$x" )) +echo $(( "x" )) + +unset a foo bar +a=(zero one two three four five six seven eight nine ten) + +echo ${a[0]} +echo ${a["0"]} + +foo=1 +echo ${a[$foo]} +echo ${a["$foo"]} +echo ${a[foo]} +echo ${a["foo"]} + +bar=2 +echo ${a[" $bar "]} +echo ${a[" bar "]} + +# tilde expansion is performed by array subscript expansion but not by posix +# style arithmetic expansion + +HOME=2 +echo $(( ~ )) + + |