shell中if-elif-else用法
#!/bin/bash
function myfun ( )
{
echo "myfun"
return 0
}
#判断标准输入中是否包含hello
#if后面接命令
if grep "hello" >/ dev / null 2 >& 1 ; then
echo "include hello"
else
echo "don't include hello"
fi
#if后面接函数调用
if myfun ; then
echo "myfun success"
else
echo "myfun error"
fi
#if后面接test语句
read T
if [ "$T" -lt "10" ] ; then
echo " T < 10"
elif [ "$T" -le "20" -a "$T" -ge "10" ] ; then
#[]中应该使用-a -o 而不是使用&& ||
echo " T >= 10 && T <= 20 "
else
echo " T > 20"
fi
function myfun ( )
{
echo "myfun"
return 0
}
#判断标准输入中是否包含hello
#if后面接命令
if grep "hello" >/ dev / null 2 >& 1 ; then
echo "include hello"
else
echo "don't include hello"
fi
#if后面接函数调用
if myfun ; then
echo "myfun success"
else
echo "myfun error"
fi
#if后面接test语句
read T
if [ "$T" -lt "10" ] ; then
echo " T < 10"
elif [ "$T" -le "20" -a "$T" -ge "10" ] ; then
#[]中应该使用-a -o 而不是使用&& ||
echo " T >= 10 && T <= 20 "
else
echo " T > 20"
fi