summaryrefslogtreecommitdiffstats
path: root/scratch/bash-3.1/tests/array-at-star
diff options
context:
space:
mode:
authorPete Travis <immanetize@fedoraproject.org>2014-09-26 14:42:22 -0600
committerPete Travis <immanetize@fedoraproject.org>2014-09-26 14:42:22 -0600
commit46c50fce0354d81d347a8055314a688fc8aa9f52 (patch)
treeb7f6c49e1225f949a9c21da6afa52fd04a2484fd /scratch/bash-3.1/tests/array-at-star
parentfe5673aed2053463a7164ec5e7b609877340c0fa (diff)
downloadrpmbuild-46c50fce0354d81d347a8055314a688fc8aa9f52.tar.gz
rpmbuild-46c50fce0354d81d347a8055314a688fc8aa9f52.tar.xz
rpmbuild-46c50fce0354d81d347a8055314a688fc8aa9f52.zip
bash sourcesobs-product
Diffstat (limited to 'scratch/bash-3.1/tests/array-at-star')
-rwxr-xr-xscratch/bash-3.1/tests/array-at-star120
1 files changed, 120 insertions, 0 deletions
diff --git a/scratch/bash-3.1/tests/array-at-star b/scratch/bash-3.1/tests/array-at-star
new file mode 100755
index 0000000..80f039d
--- /dev/null
+++ b/scratch/bash-3.1/tests/array-at-star
@@ -0,0 +1,120 @@
+# test the expansion of ${array[@]} and ${array[*]}, both quoted and
+# unquoted. the expansions should be exactly analogous to the
+# expansions of $@ and $* quoted and unquoted
+A=(a b)
+
+recho "${A[*]}"
+
+# If IFS is null, the parameters are joined without separators
+IFS=''
+recho "${A[*]}"
+
+# If IFS is unset, the parameters are separated by spaces
+unset IFS
+recho "${A[*]}"
+
+recho "${A[@]}"
+recho ${A[@]}
+
+IFS='/'
+A=(bob 'tom dick harry' joe)
+set ${A[*]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+A=(bob 'tom dick harry' joe)
+set ${A[*]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+A=(bob 'tom dick harry' joe)
+set ${A[@]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+A=(bob 'tom dick harry' joe)
+set ${A[@]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+# according to POSIX.2, unquoted $* should expand to multiple words if
+# $IFS is null, just like unquoted $@
+IFS=''
+A=(bob 'tom dick harry' joe)
+set "${A[*]}"
+recho $#
+recho $1
+recho $2
+recho $3
+
+A=(bob 'tom dick harry' joe)
+set ${A[*]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+A=(bob 'tom dick harry' joe)
+set ${A[@]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+# if IFS is unset, the individual positional parameters are split on
+# " \t\n" if $* or $@ are unquoted
+unset IFS
+A=(bob 'tom dick harry' joe)
+set ${A[*]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+A=(bob 'tom dick harry' joe)
+set ${A[@]}
+recho $#
+recho $1
+recho $2
+recho $3
+
+# but not for "$@" or "$*"
+A=(bob 'tom dick harry' joe)
+set "${A[*]}"
+recho $#
+recho $1
+recho $2
+recho $3
+
+A=(bob 'tom dick harry' joe)
+set "${A[@]}"
+recho $#
+recho $1
+recho $2
+recho $3
+
+# these should both expand the value of A to multiple words
+A=(a b c d e)
+IFS=""
+recho ${A[@]}
+recho "${A[@]}"
+
+# this example is straight from the POSIX.2 rationale and adapted to arrays
+A=(foo bar bam)
+
+recho "${A[@]}"
+recho "${A[*]}"
+
+unset IFS
+
+recho "${A[@]}"
+recho ${A[@]}
+recho "${A[*]}"