Here's a #bash pop quiz.
-
Scott Williams 🐧replied to R.L. Dane :Debian: :OpenBSD: 🍵 last edited by [email protected]
@rl_dane @decathorpe [[ supports everything [ does. [[ is the bash-ism where [ is POSIX, and test in bash is a built-in, IIRC. None of this negates what I said in my previous post.
-
R.L. Dane :Debian: :OpenBSD: 🍵replied to Scott Williams 🐧 last edited by
My understanding is that
test
|[ ]
was branched off into[[ ]]
for string/filename analysis/comparison, and(( ))
for numerical operations.[[ ]]
does seem to retain the legacy-gt
|-lt
operators oftest
|[ ]
, which is kinda cursed, admittedly. -
Scott Williams 🐧replied to R.L. Dane :Debian: :OpenBSD: 🍵 last edited by
@rl_dane @decathorpe No, what [[ adds is stuff like && and || for and/or logic and using ! for negation. It supports the same evals as test, and I should also note that "test", [, [[ are built-ins for bash, so it's not actually calling the test binary in a script unless you give the full path to it.
-
DHeadshot's Altreplied to R.L. Dane :Debian: :OpenBSD: 🍵 last edited by
@rl_dane
I just use `test` directly for everything as it makes more sense, so the above would be `test ! -z 1 && echo "true" || echo "false"`, which is actually readable!
@vwbusguy @decathorpe -
Scott Williams 🐧replied to DHeadshot's Alt last edited by [email protected]
@ddlyh @rl_dane @decathorpe test -n would be the equivalent one in this case.