Postsread more
The if Statement Secret: It Checks Exit Status, Not Booleans
Coming from almost any other programming language, you’d expect if to work on boolean expressions. You write something that evaluates to true or false, and the if decides which branch to take.
Bash works in a way that is almost, but not quite, entirely unlike that.
In Bash, if runs a command and checks its exit status. Zero means success (the “then” branch runs). Non-zero means failure (the “else” branch runs, if present).