Just as a tip, if you want to write portable
#shellscript, stick to the
#POSIX #shell:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sh.html – all the tools you can use are also documented, like e.g.
sed
:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.htmlThis POSIX shell is more or less a
#bourne shell, but specifies a few more features than the classic bourne shell had, e.g. usage of
$( ... )
for command replacement instead of only backticks.
#FreeBSD's
/bin/sh
is (AFAIK) POSIX compliant, but I'd assume even this shell can do a few things not specified in POSIX. For testing, I found
shells/bosh
very useful, it contains a few flavors of minimal shells, one of them a POSIX shell.
Regarding specifically arrays, indeed, the POSIX
sh
doesn't know them with the single exception of the "argv" array (both for the main script and any shell function), which you can also modify using
set
, but that of course has other implications. What's always available is word splitting, any variable can contain a list separated by whatever
$IFS
is set to. It defaults to whitespace. You may override
$IFS
, but that can be tricky as well, word splitting is used a lot, so expect surprising effects.

Most of the time, it's best to find a way to solve your problem
without arrays.
