手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>网站运营>建站经验>列表

Bourne Shell及shell编程(1)

来源:互联网 作者:west263.com 时间:2008-04-16
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

相同
便于阅读和组织, Bourne Shell在使用test测试时使用了另一种方法:用方括号将
整个
test测试括起来:

$ int1=4
$ [ $int1 -gt 2 ]
$ echo $?
0

例: 重写unload程式,使用test测试
#!/bin/sh
#unload - program to backup and remove files
#syntax: unload directory

#check arguments
if [ $# -ne 1 ]
then
echo "usage: directory"
exit 1
fi

#check for valid directory name
if [ ! -d "" ]
then
echo " is not a directory"
exit 2
fi

cd

ls -a | cpio -o > /dev/rmt/0h

if [ $? -eq 0 ]
then
rm -rf *
else
echo "A problem has occured in creating backup"
echo "The directory will not be ereased"
echo "Please check the backup device"
exit 3
fi
# end of unload

在如上示例中出现了exit, exit有两个作用:一是停止程式中其他命令的执行,二

配置程式的退出状态

g. if嵌套及elif结构
if command
then
command
else
if command
then
command
else
if command
then
command
fi

fi
fi

改进:使用elif结构
if command
then
command
elif command
then
command
elif command
then
command
fi

elif结构同if结构类似,但结构更清淅,其执行结果完全相同.

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!