Bashisms vs POSIX Shell Features
Bashisms vs POSIX Shell Features
| Feature | GNU Bash | POSIX sh (/bin/sh) |
|---|---|---|
| Test syntax | [[ $a == $b ]] |
[ "$a" = "$b" ] |
| Arrays | arr=(a b) |
None (use $@ or IFS) |
| String replacement | ${var//find/replace} |
echo "$var" \| sed 's/find/replace/g' |
| Function keyword | function myfunc() { } |
myfunc() { } |
| Local variables | local x=1 |
Not standard POSIX (widely supported) |
| Regex match | [[ $v =~ pattern ]] |
Use expr or grep |
Audit scripts for accidental bashisms using checkbashisms script.sh.