I usually write my scripts in bash. I tell other people to run them in bash, and I use #!/usr/bin/env bash as the shebang line.
When I read about shell scripting I often find comments with suggestions of "portable" solutions that do not use "bashisms". A portable shell script seems to be a one that can be run in any Bourne Shell derivative, eg. bash, ksh, or csh.
To me this seems a bit weird. Why would you not know what shell you run your script in? What is the actual use of portable shell scripts? If you feel like using bash features, why not simply use bash?
I assume that there are common situations when portability is required, for why would it otherwise be mentioned so often? Perhaps certain environments require portability for historical reasons - I don't know - but I'm interested in finding out what these environments are.
Why would you not know what shell you run your script in?
bash features work the same even across different versions of bash (see the compat31, compat32, compat40, compat41 options).Some common examples of non-bash usage:
dash is the system shell for Debian and Ubuntubash 3.2 instead of 4.xkshbash needs to be installed separately on FreeBSD systems.