You solve it by not using sh
.
The PIPESTATUS
variable specifically, and the $
array syntax in general, are features specific to the Bash shell. They do not exist in POSIX sh, and even shells that do have arrays might use a different syntax.
It just happens that some Linux distributions symlink their /bin/sh
to Bash. Other distributions, however, symlink it to dash, Debian Almquist Shell. Both are compatible with POSIX sh scripts, but only Bash accepts the $
syntax.
So if you want to use it, run bash -c "…"
instead.