- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
第5章Shell编程
逻辑判断式 5.逻辑与(and)和或(or) 逻辑卷标 含义 逻辑与 || 逻辑或 运算符 运算符 含义 运算符 含义 = 等于 -gt 大于 != 不等于 -le 小于或等于 小于 -ge 大于或等于 大于 -a 双方都成立(amd) -eq 等于 -o 单方成立(or) -ne 不等于 -z 空字符串 -lt 小于 -n 非空字符串 5.8 条件判断 if…then…fi 语法: if [ 条件判断一 ] (||) [ 条件判断二 ] ;then elif [ 条件判断三 ] (||) [ 条件判断四 ]; then else fi 案例一 #!/bin/bash #This program is used to study if then #创建日期:2002/06/27 #Written by VBird echo “Press y to continue.” read yn if [ “$yn” = “y” ] ; then echo “script is running……..” else echo “STOP!” fi [root @test test]# sh test06-ifthen.sh 案例二 #!/bin/bash #This program is used to study if then #创建日期:2002/06/27 #Written by VBird echo “Press y to continue.” read yn if [ “$yn” = “y” ] || [ “$yn” = “Y” ]; then echo “script is running……..” else echo “STOP!” fi [root @test test]# sh test07-ifthen.sh 案例三 #!/bin/bash #set parameters in the if then #创建日期:2002/06/27 #Written by VBird if [ “$1” = “hello” ] ; then echo “Hello! How are you ?” elif [ “$1” = “ ” ] ; then echo “You MUST input parameters” else echo “The only accept parameter is hello” fi [root @test test]# sh test08-ifthen.sh hello 案例四 #!/bin/bash #program: Using to study the [ if … then … fi ]program #创建日期:2002/06/27 #Written by VBird #1.print the program’s work in your screen echo “Now, the services of your Linux system will be detect!” echo “The www, ftp , ssh , and sendmail + pop3 will be detect!” echo “ ” #2. www www=` netstat -an| grep LISTEN| grep :80 ` if [ “$www” != “” ];then echo “WWW is running………” else echo “WWW is NOT running……” fi #3. ftp ftp=` netstat -an| grep LISTEN| grep :21 ` if [ “$ftp” != “” ];then echo “FTP is running………” else echo “FTP is NOT running……” fi #4. ssh ssh=` netstat -an| grep LISTEN| grep :22 ` if [ “$ssh” != “” ];then echo “SSH is running………” else echo “SSH is NOT running……” fi [root @test test]# sh port.sh #5. sendmail+pop3 smtp=` netstat -an| grep LISTEN| grep :25 ` if [ “$smtp” != “” ] [ “$pop3” != “” ] ;then echo “sendmail is OK!” elif [ “$smtp” != “”
文档评论(0)