This is motivated by the fact that the popularity of bats is increasing
since the creation of bats-core/bats-core.
The code is a cherry-pick of koalaman/shellcheck/bats branch.
Fixkoalaman/shellcheck#417.
Pattern matching in "do" requires a MonadFail context, which we don't have in
pure code. Instead, we'll use "case-of" to bind the part of the state that
we're interested in.
It used to only treat all trailing variables in read as varaible
declarings, but an array variable can be declared in other positions:
read -a foo -r
foo is a declared variable, and multiple such variables can be declared.