shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

Provide a bash4 compatibility mode

Open vvug opened this issue 6 years ago • 3 comments

It would be nice if shellcheck supported a bash4 compatibility mode. I recently wrote a script on my system using bash5 and using the EPOCHSECONDS variable; no problems were spotted by shellcheck, the script works fine. The problem is that I'm going to run this script on systems where only bash4 is available. With a bash4 compatibility mode I could have used shellcheck to be sure that my script was bash4-safe.

vvug avatar Oct 27 '19 11:10 vvug

Every version of bash has introduced new features though. Do you want a bash 4.4, 4.3, 4.2, 4.1, 4.0, 3.x (still in use on Mac OS) mode? Bash 5 actually introduced relatively little in new features compared to many of the 4.x point releases (e.g. namerefs in 4.3).

If you need a script to work on old bash versions, you can check here for a summary of what's new. Or if your script relies on a newer feature, you can make it check $BASH_VERSION/$BASH_VERSINFO at runtime and exit with an error message if the bash version is incompatible.

automorphism88 avatar Dec 24 '19 18:12 automorphism88

I really just need a way to find a way where I'm using features that aren't available on 3.2. Or features that are available in 3.2 but might have changed behaviors in newer versions. I think (set -e) changed behavior in 4.x within conditionals and piped commands?

trothwell avatar Jan 24 '23 19:01 trothwell

I think a 3.2 boundary would make sense considering that's the version locked on Darwin. One is quite likely to be running on 3.2 or latest. (If one is able to upgrade at all, they've likely upgraded to something fairly recent. If they haven't upgraded at all, they'd be on 3.2.) Clearly this doesn't hold in all cases (like the OP), but it probably hits the 80/20 rule. Which would be enough to have warnings for 3.2 compatibility be useful.

jasonkarns avatar Jun 10 '24 13:06 jasonkarns