conditional judgment of arithmetic operation [] [[]]:-eq-ne-Lt-le-gt-GE
(( )):
>
<
>=
<=
=
[[Email protected] ~]# if ((2 = = 3)); then echo ' 123 '; Fi
[[Email protected] ~]# if ((2 >= 3); then echo ' 123 '; Fi
[[Email protected] ~]# if ((2 <= 3); then echo ' 123 '; Fi
123
[[Email protected] ~]# if ((2 < 3)); then echo ' 123 '; Fi
123
[[Email protected] ~]# if ((2 > 3)); then echo ' 123 '; Fi
Conditional determination of strings -z-n===!=<> file attributes -f-D-C-W -L-x-e-b-R
#!/bin/bash
If [-e demo.sh];then
echo "File exists"
Fi
Fpath= "/etc/passwd"
If [-e $fpath];then
echo file exists;
Else
echo File no exists;
Fi
[-E "/etc/hosts"] | | (Echo '/etc/hosts not exist "; exit 1)
If ["$?"-eq 1];then
Exit
Fi
echo "/etc/hosts file exists"
Declare-i A
A=20
If [$a-eq];then
Echo "var a 20"
Fi
If [$a-gt];then
Echo ' var >10 ';
Fi
If ["$LOGNAME"! = "ROOT"];then
echo "Root"
Fi
If ["Bill" > "Apple"];then
echo "BILL >apple"
Fi
Str= "Bill"
If [-N $str];then
echo "234"
Fi
#!/bin/bash
num1=100
num2=200
if (($NUM 1 > $NUM 2)); then
echo "OK"
Else
echo "Ok1"
Fi
#!/bin/bash
dir=/tmp/20140909
if [!-D $Dir];then
Mkdir-p $Dir
Echo-e "\033[32mthis $Dir exist\033[0m"
Else
Echo-e "\033[32mthis $Dir is Exist,please exit.\033[0m"
Fi
#!/bin/bash
Files=/tmp/test.txt
If [-F $FILES];then
echo "OK" >> $FILES
Else
Cat $FILES
Fi
-A: Logical expression-a logical expression
-O: Logical expression-o logical expression
LINUX Shell condition judgment