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
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
相关文章推荐
- shell 条件判断语句参数介绍
- shell 嵌套条件语句时,尽量把靠近两次判断
- Shell条件判断语句上
- shell基础之二:条件判断语句if、case及read命令,
- 25_Shell语言――――if条件判断之组合判断(与、或、非)和多分支if语句
- shell脚本编写 之 条件选择,条件判断,循环语句
- Shell 编程5(条件判断语句if)
- Shell中的条件判断语句if~then~fi
- shell 条件判断语句整理
- shell之条件测试和判断语句
- shell 语句中条件判断常用值
- 21_Shell语言――条件判断一之执行状态返回值、单分支条件判断语句
- shell脚本编程中条件判断语句中各个参数的含义
- 04 shell条件测试和判断语句
- 22_Shell语言――――双分支条件判断语句、表达式判断、嵌套
- shell脚本编程:条件判断if语句使用小结
- shell中条件判断if中的-z到-d的意思
- shell脚本中的算术运算和条件测试语句
- C语言奇思妙想:求1+2+…+n,要求不能使用乘除法、for、while、if、else、s witch、case 等关键字以及条件判断语句(A?B:C)
- Linux shell脚本编程if语句的使用方法(条件判断)