当前位置: 首页 > news >正文

便宜的做网站/哈尔滨seo优化公司

便宜的做网站,哈尔滨seo优化公司,做网站培训班,网站排名优化服务if 语句通过关系运算符判断表达式的真假来决定执行哪个分支。Shell 有三种 if ... else 语句: if ... fi 语句;if ... else ... fi 语句;if ... elif ... else ... fi 语句。1) if ... else 语句 if ... else 语句的语法: if [ ex…

if 语句通过关系运算符判断表达式的真假来决定执行哪个分支。Shell 有三种 if ... else 语句:

  • if ... fi 语句;
  • if ... else ... fi 语句;
  • if ... elif ... else ... fi 语句。

1) if ... else 语句

if ... else 语句的语法:

if [ expression ]
thenStatement(s) to be executed if expression is true
fi

如果 expression 返回 true,then 后边的语句将会被执行;如果返回 false,不会执行任何语句。

最后必须以 fi 来结尾闭合 if,fi 就是 if 倒过来拼写,后面也会遇见。

注意:expression 和方括号([ ])之间必须有空格,否则会有语法错误。

举个例子:

  1. #!/bin/sh
  2. a=10
  3. b=20
  4. if [ $a == $b ]
  5. then
  6. echo "a is equal to b"
  7. fi
  8. if [ $a != $b ]
  9. then
  10. echo "a is not equal to b"
  11. fi

运行结果:

a is not equal to b

2) if ... else ... fi 语句

if ... else ... fi 语句的语法:

if [ expression ]
thenStatement(s) to be executed if expression is true
elseStatement(s) to be executed if expression is not true
fi

如果 expression 返回 true,那么 then 后边的语句将会被执行;否则,执行 else 后边的语句。

举个例子:

  1. #!/bin/sh
  2. a=10
  3. b=20
  4. if [ $a == $b ]
  5. then
  6. echo "a is equal to b"
  7. else
  8. echo "a is not equal to b"
  9. fi

执行结果:

a is not equal to b

3) if ... elif ... fi 语句

if ... elif ... fi 语句可以对多个条件进行判断,语法为:

if [ expression 1 ]
thenStatement(s) to be executed if expression 1 is true
elif [ expression 2 ]
thenStatement(s) to be executed if expression 2 is true
elif [ expression 3 ]
thenStatement(s) to be executed if expression 3 is true
elseStatement(s) to be executed if no expression is true
fi

哪一个 expression 的值为 true,就执行哪个 expression 后面的语句;如果都为 false,那么不执行任何语句。

举个例子:

  1. #!/bin/sh
  2. a=10
  3. b=20
  4. if [ $a == $b ]
  5. then
  6. echo "a is equal to b"
  7. elif [ $a -gt $b ]
  8. then
  9. echo "a is greater than b"
  10. elif [ $a -lt $b ]
  11. then
  12. echo "a is less than b"
  13. else
  14. echo "None of the condition met"
  15. fi

运行结果:

a is less than b


if ... else 语句也可以写成一行,以命令的方式来运行,像这样:

  1. if test $[2*3] -eq $[1+5]; then echo 'The two numbers are equal!'; fi;


if ... else 语句也经常与 test 命令结合使用,如下所示:

  1. num1=$[2*3]
  2. num2=$[1+5]
  3. if test $[num1] -eq $[num2]
  4. then
  5. echo 'The two numbers are equal!'
  6. else
  7. echo 'The two numbers are not equal!'
  8. fi

输出:

The two numbers are equal!

test 命令用于检查某个条件是否成立,与方括号([ ])类似。

转载于:https://www.cnblogs.com/dongdong230/p/4201494.html

http://www.jmfq.cn/news/5056867.html

相关文章:

  • 智慧团建手机版登录注册入口/seo技术 快速网站排名
  • 网站改造设计方案/全国唯一一个没有疫情的城市
  • 外贸b2b网站大全排名/百度快照推广排名
  • 网站系统优点/外贸独立站怎么建站
  • 做网站订金是多少钱/关键词百度指数查询
  • 网站后台登录界面/网站代搭建维护
  • 免费网站建站排行榜/上海网络推广服务
  • 网站建设教程赚找湖南岚鸿认 可/百度网址安全检测
  • 时时彩网站建设开发/营销培训班
  • 宁波网站建设制作公司排名/什么是整合营销并举例说明
  • 建筑设计专业是干什么的/seo薪酬如何
  • 做毕业证教育网站/百度深圳总部
  • 做网站的模版/怎么找推广渠道
  • 做网站每年交服务费/电子商务网站建设方案
  • 如何让网站快速被收录/怎么样拓展客户资源
  • 淮北网站建设制作/seo点击器
  • wordpress主题安装/百度上如何做优化网站
  • springboot社交网站开发/代运营公司可靠吗
  • 如何做免费电影网站/广告公司推广文案
  • 网站的开发环境是什么/seo点击排名工具有用吗
  • 空滤网站怎么做/抖音关键词排名优化
  • 福建微网站建设公司/bt兔子磁力天堂
  • 网站建设必须要服务器么/2022年seo还值得做吗
  • 宁波哪家公司做网站好/外贸怎么建立自己的网站
  • 大做网站/企业网站推广方案
  • 北海住房和城乡建设部网站/百度应用
  • 台州网站建设方案/金戈枸橼酸西地那非片
  • 网站开发网站制作报价单/怎么创建自己的网址
  • 找工程去哪个网站/系统优化大师免费版
  • 菏泽建设/云速seo百度点击