[ 来源: | 作者: | 时间:2007-07-17 | 收藏 | 推荐 ] 【大 中 小】
iflistthenlist[eliflistthenlist]...[elselist]fi
几种可能的写法
--------------------------------------------------------------------------------
第一种
iflistthen
dosomethinghere
fi
当list表述返回值为True(0)时,将会执行"dosomethinghere"。
例一:当我们要执行一个命令或程式之前,有时候需要检查该命令是否存在,然後才执行。
if[-x/sbin/quotaon];then
echo"TurningonQuotaforrootfilesystem"
/sbin/quotaon/
fi
例二:当我们将某个档案做为设定档时,可先检查是否存在,然後将该档案设定值载入。
#Filename:/etc/ppp/settings
PHONE=1-800-COLLECT
#!/bin/sh
#Filename:phonebill
if[-f/etc/ppp/settings];then
source/etc/ppp/settings
echo$PHONE
fi
执行
[foxman@foxmanppp]#./phonebill
1-800-COLLECT
--------------------------------------------------------------------------------
第二种
iflistthen
dosomethinghere
else
dosomethingelsehere
fi
例三:Hostname
#!/bin/sh
if[-f/etc/HOSTNAME];then
HOSTNAME=`cat/etc/HOSTNAME`
vd;k;l www.it55.com rdfg
(编辑:IT资讯之家 www.it55.com)