Portability Considerations for Arrays

Updated

October 31, 2026

Portability Considerations for Arrays

Arrays are not part of the POSIX standard. If a script runs under /bin/sh on Debian (dash) or Alpine (ash), arrays will fail with syntax errors.

# POSIX workaround 1: Use positional parameters
set -- "arg 1" "arg 2 with spaces" "arg 3"
for item in "$@"; do
    echo "$item"
done

# POSIX workaround 2: Delimited string with IFS
list="item1:item2 with space:item3"
old_ifs=$IFS
IFS=":"
set -f
for item in $list; do
    echo "$item"
done
IFS=$old_ifs
set +f