junxnone / xwiki

https://junxnone.github.io/xwiki/
0 stars 0 forks source link

Programing Shell if #102

Open junxnone opened 5 years ago

junxnone commented 5 years ago

if 判断

i=1
if [ $i -lt 10 ]
then
    echo "xxx"
else
    echo "xxx"
fi

注意 $i 和 10 前后都有空格

UseCase

判断变量是否是 0

if [ $var -eq 0 ];then
    echo "$var is 0"
else
    echo "$var is not 0"
fi
if [ $var == 0 ]
then
    echo "$var is 0"
else
    echo "$var is not 0"
fi

判断变量是否为字符串xxx

if [ $var == 'abc' ]
then
    echo "$var is abc"
else
    echo "$var is not abc"
fi

判断变量是否相等

if [ $var == $var2 ]
then
    echo "$var = $var2"
else
    echo "$var != $var2"
fi
junxnone commented 4 years ago

junxnone/linuxwiki#23