koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.23k stars 1.77k forks source link

Feature Request: Check for version-specific Bash feature compatibility #2850

Open gwerbin opened 11 months ago

gwerbin commented 11 months ago

GNU Bash has made some significant changes across versions. Sometimes we want to write scripts that work on a wide range of versions, e.g. MacOS 12.4 still ships with Bash 3.x.

There are several feature matrices out there for Bash, but they require manual verification and inspection, which is exactly what Shellcheck is good for!

Documentation resources include:

It would be very useful if Shellcheck allowed us to specify a specific Bash version, e.g. shell=bash:3.x, and could then check for feature compatibility.

For example, if I declare shell=bash:3., the mapfile and readarray builtins should be prohibited unless I define my own shell functions of the same name. If the user happens to have an executable program on their system of the same name, they could opt to disable this particular incompatibility warning (or they could use env mapfile to work around the ambiguity).

Of course this could be extended to other shells in principle, but my immediate use case is Bash, and I assume that probably applies to most other Shellcheck users out there.

Finally, thank you for the excellent tool! Shellcheck has been a productivity booster and reliable safeguard in my work, and I am grateful for its existence.

dalisoft commented 5 months ago

Could be nice to see such feature