Why when I type in bash: if [ false ]; then echo 'ok'; fi;
I get ok
string as a result? The similiar result I can get also when using variable: ok=false; if [ $ok ]; then echo 'ok'; fi;
if [ false ]
is equivalent to if [ -n "false" ]
- it's testing the length of the string. If you are trying to test the exit code of /bin/false
, use if false
(no [
, which for many, but not all, modern shells is a shell builtin roughly equivalent to /usr/bin/[
or /usr/bin/test
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With