您的位置:首页 > 运维架构 > Shell

shell条件判断 条件为何值时判断语句为真

2012-11-30 14:00 447 查看
#!/bin/bash

if [ 0 ]

then

echo "0 is true"

else

echo "0 is flase"

fi

if [ 1 ]

then

echo "1 is true"

else

echo "1 is flase"

fi

if [ -1 ]

then

echo "-1 is true"

else

echo "-1 is flase"

fi

if [ 10 ]

then

echo "10 is true"

else

echo "10 is flase"

fi

if [ ]

then

echo "NULL is true"

else

echo "NULL is flase"

fi

if [ xyz ]

then

echo "xyz is true"

else

echo "xyz is flase"

fi

xyz=

if [ -n "$xyz" ]

then

echo "$xyz is true"

else

echo "\$xyz is flase"

fi

exit 0

# ./test.sh 输出判断

0 is true

1 is true

-1 is true

10 is true

NULL is flase

xyz is true

$xyz is flase
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: