免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 949 | 回复: 0
打印 上一主题 下一主题

shell测试 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-23 11:44 |只看该作者 |倒序浏览
1.通过shell判断dhcp的结果
dhclient  2>&1 | grep DHCPOFFERS
echo "result:$?"

2.循环mknod
for ((i=0;i
mknod "/dev/fusion/$i" c 250 "$i"
done

3.shell基本测试
!/bin/bash
#########################  打开shell执行语句跟踪     ###############
set -x
#########################   sub bash call,括号中的语句相当于一个新的shell调用    #########################
var=$(pwd)
#########################   使用let赋值     #########################
a=10
let a+=1        #let a=a+1  也可以
echo "a=$a"
#########################  使用$#获取传入脚本参数的个数      #########################
if [ $# -le 2 ]         # -le 小于 -eq等于 -ne 不等于
then
        echo "then number of param less than 2"
fi
#########################  !取反操作符      #########################
if [ $# != 2 ]
then echo "the number of param not 2"
fi

#########################  测试变量非空      #########################
if [ -n $1 ]
then echo "param1 not null"
fi
#########################  测试 0 1 -1 null未定义的变量   是否为 ture      #########################
if [ 0 ]
then echo "0 is ture"
else echo "0 is false"
fi
if [ 1 ]
then echo "1 is ture"
else echo "1 is false"
fi
if [ -1 ]
then echo "-1 is true"
else echo "-1 is false"
fi
if []
then echo "null is true"
else echo "null is false"
fi
if [ $undefine_var ]
if [ $undefine_var ]
then echo "undefine variable is ture"
else echo "undefine variable is false"
fi
#########################  逻辑与/或  操作      #########################
condition1=1
condition2=
#       if [ "$condition1" && "$condition2" ] 错误写法
if [ $condition1 ]&&[ $condition2 ]
then echo "condition1 && condition2 is ture"
else echo "condition1 && condition2 is false"
fi
if [ $condition1 ]||[ $condition2 ]
then echo "condition1 || condition2 is ture"
else echo "condition1 || condition2 is false"
fi

#########################  test read,shell 输入     #########################
read input
echo "your input is: $input"
exit 0
#########################        #########################


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/61758/showart_1008990.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP