Bash syntax running under /bin/sh
Common${VAR^^}, ${VAR,,}, ${VAR:offset:length}, ${VAR//a/b} and arrays are bash features that dash rejects.
Confirm
head -1 script.sh ls -l /bin/sh
#!/bin/sh, or a sh script.sh call, on a system where /bin/sh points to dash
Fix
- Start the script with #!/usr/bin/env bash and run it directly or with bash script.sh, not sh script.sh.
- Or rewrite in POSIX form: printf '%s\n' "$V" | tr '[:lower:]' '[:upper:]' for upper case, printf '%.3s' "$NAME" for the first three characters, ${NAME%%.*} to cut at the first dot.
#!/usr/bin/env bash
Reproduced on Ubuntu 24.04: the same file run with bash printed HELLO.