#!/bin/bash -x if [ "A" = "B" ] ;then echo"A" else echo"B" fi #output:B if [ "A" = "A" ] ;then echo"A" else echo"B" fi #output:A if [ "A" == "B" ] ;then echo"A" else echo"B" fi #output:B if [ "A" == "A" ] ;then echo"A" else echo"B" fi #output:A
不等于 !=
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash -x if [ "A" != "B" ] ;then echo"A" else echo"B" fi #output:A if [ "A" != "A" ] ;then echo"A" else echo"B" fi #output:B
空串 -z
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash -x if [ -z "A" ] ;then echo"A" else echo"B" fi #output:B if [ -z "" ] ;then echo"A" else echo"B" fi #output:A
非空串 -n
1 2 3 4 5 6 7 8 9 10 11 12 13
#!/bin/bash -x if [ -n "A" ] ;then echo"A" else echo"B" fi #output:A if [ -n "" ] ;then echo"A" else echo"B" fi #output:B