Since you want to use POSIX shell and POSIX shell does not support arrays, you can "emulate" array in this way:
set -- 'A' 'B'
Then you will have the only "array" available in POSIX shell ("$@") that contains A ($1) and B ($2).
And you can pass this array to another function, such as:
test() {
echo "$2"
}
set -- 'A' 'B C'
test "$@"
If you need to save the array you can use the following function:
arrsave() {
local i
for i; do
printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"
done
echo " "
}
And use it in the following way:
set -- 'A' 'B C'
# Save the array
arr=$(arrsave "$@")
# Restore the array
eval "set -- $arr"
#!/bin/shand not#!/bin/bash. Arrays are not supported in POSIX shells, but they are in Bash.shdoesn't support arrays. If you need arrays, switch to Bash.