/bin/sh
is hardly ever a Bourne shell on any systems nowadays (even Solaris which was one of the last major vendors to include it have now switched to a POSIX sh for their /bin/sh in Solaris 11). /bin/sh
was the Thomson shell in the early 70s. The Bourne shell replaced it in Unix V7 in 1979.
/bin/sh
has been the Bourne shell for many years thereafter (or the Almquist shell, a free reimplementation on BSDs).
Nowadays, /bin/sh
is more commonly an interpreter or another for the POSIX sh
language which is itself a subset of the language of ksh88 (and a superset of the Bourne shell language with some incompatibilities).
The Bourne or POSIX sh don't have arrays. Or rather they have only one array: the positional parameters ($1
, $2
, $@
, so one array per function as well).
ksh88 did have arrays which you set with set -A
, but that didn't get specified in the POSIX sh as the syntax is awkward and not very usable.
Other shells with array/lists variables include: csh
/tcsh
, rc
, es
, bash
(which mostly copied the ksh syntax the ksh93 way), zsh
, fish
each with a different syntax (rc
the shell of the once to-be sucessor of Unix, fish
and zsh
being the most consistent ones)...
In standard sh
(also works in modern versions of the Bourne shell):
set '1st element' 2 3 # setting the array
set -- "$@" more # adding elements to the array
shift 2 # popping elements from the array
printf '<%s>\n' "$@" # passing all the elements of the $@ array
# as arguments to a command
for i do # looping over the elements of the $@ array ($1, $2...)
printf 'Looping over "%s"\n' "$i"
done
printf '%s\n' "$1" # accessing individual element of the array.