The only array-like structure in a POSIX shell is the $@ list whose elements can be accessed independently with $1,$2,$3,... The number of elements available is given by $#.
$@ elements can be modified using set and shift.
The top-level and each function call has its own separate $@ array which is initialised to the arguments received by the script/function when it is called.
Using set or shift inside a function does not affect the top-level $@.
It is possible to save all the original elements of $@ somewhere but I don't believe there is way to use the result in a form as simple as bash's "${arr[@]}" syntax. (Individual elements may accessed without too much effort but not, trivially, the array as a whole.)
However, by appropriately reloading/manipulating the elements of $@ it can be used directly, although performing the manipulation is likely to be rather tedious.
A quick search for ways to accomplish the saving found these approaches:
Rich's code from the second link is probably the simplest and looks like:
save(){
for i do
printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/"
done
echo " "
}
and is used as:
myarray=$(save "$@")
set -- foo bar baz boo
# ... do stuff with new $@ ...
eval "set -- $myarray"
The eval is safe since $myarray expands to a list of single-quoted strings.
See
how-to-use-pseudo-arrays-in-posix-shell-script
for a more efficient and arguably easier to understand awk implementation of this idea. which can be made slightly more efficient still by moving the string concatenation out of the loop so it's only done once:
save() {
LC_ALL=C awk -v q=\' '
BEGIN {
escq = q "\\" q q
qfmt = q "%s" q
for ( i=1; i<ARGC; i++ ) {
gsub(q, escq, ARGV[i])
printf qfmt, ARGV[i]
}
print ""
}
' "$@"
}