I am used to the C/C ++ programming environment, and then switched to shell programming, there is always a strange feeling.
The general if-then-else Function Format in shell is as follows:
If condition 1
Then command 1
Elif condition 2
Then command 2
Else command 3
Fi
In Linux
If the exit status of the command is 0, the exit is successful and there is no error;
If the exit status is 1, the exit fails, and an error occurs somewhere.
If-then-else-FunctionIn, condition 1 is a condition test. If condition 1 returns 0, the test is true, and command 1 is executed. If condition 1 returns 1, Elif is executed.
That is to say, the criterion for determining whether the test is successful is if, rather than the return value.
This is a little different from C/C ++. If you don't pay attention to it, you will get it wrong.
For more information, see:
Linux and unix_shell programming guide 18.3