Most code I write is in PHP. I have recently started learning shell scripting. Most of the resources and tutorials that I've come across are specific to Bash. Some warn about bashisms and some don't. I've been reading a lot on here and Stack Overflow.
Whenever an answer uses bashisms, someone will inevitably comment to say:
You shouldn't use <insert bashism here>. It's not portable.
This happens even when the question was tagged with bash. To me, that's like telling a PHP programmer that they shouldn't use code that's new in PHP 5 because it can't be used with PHP 4. Or telling someone they shouldn't write something for Mac because it can't be used on Windows.
When I write in PHP, I pick a minimum requirement and I write forward-compatible code. I don't worry about making it backward-compatible.
If I use #!/bin/bash as the shebang, why shouldn't I use bashisms? I'm starting to get the impression that some people just like to bash bashisms (pun intended) just for the sake of it.
People often use bash and shell interchangeably - probably due to the fact that bash is the default shell on many systems. So I can understand adding a comment to warn that the code uses bashisms, but I don't understand the implication that it's wrong to use them.
Obviously, if I am writing a script strictly for personal use I can write it in whatever language I want. But I'd like to think some of the code I write could be useful to others.
I tried searching for an answer to my question before posting. I found a lot of information about how to test for portability, but couldn't find anything about when it's important to do so.
So, when is it important to write portable scripts?
For example,
- what types of scripts should be as portable as possible?
- how common are systems that do not have Bash installed?
- if the system has Bash installed, will it also have the GNU version of find and other utilities?
bashtag alone, someone comments "It's bashism and not portable". When I answer a question that's taggedC, I don't care whether it's portable toJavaor not.bashspecific feature, and not portable, just as I would point out that a GNU specific extension is being used for some utility (even though the question was tagged as Linux). I've never seen anyone say "this is a bashism and you should never use it".