4 ms·
Here is a question: what is the point of if test x$var = val ; ... instead of using the [ command? Some years ago, I checked: the [ alias for test was alr
by kazinator 4y ago
Here is a question: what is the point of
if test x$var = val ; ...
instead of using the [ command?
Some years ago, I checked: the [ alias for test was already in the Bourne shell in 1979.
Assume the year is 1999. What real portability problem do you solve by avoiding [ in favor of test?
Real meaning that the rest of the script, and the software stack the script is related to, runs on a system where [ wouldn't work.
- dundarious 4y agoI always use test: - it looks like every other thing in sh (`[` is the outlier) - it prevents confusion like putting `&&` inside the `[ ... ]` brackets (understandable that `[` works that way if you think about it, but it’s another way it’s an outlier) - mildly discourages use of one particular bash-ism, `[[`, as it works slightly differently, and I prefer POSIX sh unless there is a good justification - it doesn’t require a closing `]` I don’t use it for what I think you mean by portability, that is, because `test` exists whereas `[` does not, or anything like that.