shellcheck
shellcheck copied to clipboard
Rule: Warn on bash-style array syntax for non-bash-family shells
For new checks and feature suggestions
- [x] https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
- [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
#!/bin/sh
echo $somearray[@]
echo $somearray[*]
These lines may be fine in bash, zsh, dash, posh, etc., but the lines are invalid in (POSIX) sh, ksh, and so on.
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
Bash array syntax used, though a strict POSIX sh interpreter was detected.
(you need to add the curly braces to get the error. SC1087 (error): Use braces when expanding arrays, e.g. ${array[idx]} (or ${var}[.. to quiet). )