If statement 1.1 if statement explanation
If is a judgment statement, if the action is similar to [], the general judgment is more or the execution of the statement is more, then will use if
1.2 If format
First format
if [ 判断条件 ];then 内容else 内容fi
Second form, multiple judgments
if [ 判断条件 ];then 内容elif [ 判断条件 ];then 内容else 内容fi
1.3 Precautions
There must be spaces on both sides of [] after the IF statement
1.4 If example
1.if judgment
Determine if/root/a.txt exists, if present, echo 0, if not present, Echo1
#!/bin/bash -if [ -f /root/a.txt ];then echo 0else echo 1fi
2.if...elif...else ...
Determine if/root/a.txt exists, if present, then echo A.txt, determine if/root/b.txt exists, if present, then echo B.txt, if a.txt and b.txt do not exist, then output error
#!/bin/bash -if [ -f /root/a.txt ];then echo "a.txt"elif [ -f /root/b.txt ];then echo "b.txt"else echo "error"fi
The "shell" Linux shell if statement is detailed