Join Nostr
2026-03-09 15:46:42 UTC

Rebane on Nostr: fun linux fact: the `if` shell built-in just executes the command you give it and ...

fun linux fact:
the `if` shell built-in just executes the command you give it and looks at its exit code

so how can you do stuff like `if [ $a -gt 10 ]`?

well, [ is just a program usually in /bin/[ that takes the arguments ($a, -gt, 10, ]) and returns an exit code accordingly

this is also why you need the spaces between everything as well as quoting - they're ordinary arguments and need to be provided as such

also note that many shells do actually have similar shell built-ins such as [[ ]] and (( )), which are not stand-alone programs like [ is