Bad string substitution error
could be related to bash version :
linux - String replacement in bash - bad substitution error
substitution works fine in Bash 4.2.8 (and looks fine according to the documentation)
If you’re doing sh script.sh you may well be running it with Dash
https://hybriddbablog.com/2021/01/25/bash-bad-substitution-upgrade-your-bash-version/