In these days I spent a lot of time reading various articles and guides about scripting (most of all in bash).
One of the first things that came up is that the best thing to do is sticking to POSIX, for portability.
Anyway, what I couldn't get straight is the standard way to make a conditional statement...
I would like to ignore test
in this post and discuss [
and [[
instead.
What I found is that [
is a bit dated, but every shell support it (older as alias of /bin/test/
, "newer" as part of the shell themselves). On the other hand, almost every tutorial I found use [[
, and, when asked, the reason is something like "Bash is default in most of Linux distros, so it's like a standard".
There are, of course, a lot of differences between them and personally I found [[
easier to use.
So here's the question: "What is the standard way to make a conditional statement?"
And if a standard way isn't defined: "What is the best way?"
When you answer, keep in mind that what I have to achieve is portability, not readability or easiness...
If possible, support your answer with facts/docs, but I'd like to read also personal opinions. For example, I would like to know what you think about "bash is a standard de facto" and if it is really safe to use it as a standard rather than only POSIX rules.
Thanks for your time [:
Aucun commentaire:
Enregistrer un commentaire