3 ms·
I'm not defending shell, just pointing out how it works. One of my biggest annoyances with shell is that there are these magic programs such as [ that pretend
by cduzz 6y ago
I'm not defending shell, just pointing out how it works.
One of my biggest annoyances with shell is that there are these magic programs such as [ that pretend to be part of the language but aren't.
If if $var has an exit status (because perhaps you insanely want to have var be some program set elsewhere) your if statement would work....
These other examples have operators (test or similar expanded builtins), and those set the exist status that the if block reads.
so
grep -q hacker < /etc/passwd
if [ $? -eq 0 ] ; then echo hackd! ; fi
is an indirect way of saying:
if grep -q hacker < /etc/passwd ; then echo hackd! ; fi
Shell is terrible, but the way people use it makes it even worse because the sugar hides what's actually going on.