File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed
Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -272,7 +272,7 @@ for i in ${array[@]};do echo $i ;done # 遍历数组,数组元素为空,没
272272> 说明:图片来自《菜鸟教程》
273273
274274 Shell 编程支持下面几种运算符
275-
275+
276276- 算数运算符
277277- 关系运算符
278278- 布尔运算符
@@ -380,10 +380,10 @@ a 不等于 b
380380#! /bin/bash
381381a=3;
382382b=9;
383- if [ $a = $b ]
383+ if [ $a -eq $b ]
384384then
385385echo " a 等于 b"
386- elif [ $a > $b ]
386+ elif [ $a -gt $b ]
387387then
388388echo " a 大于 b"
389389else
394394输出结果:
395395
396396` ` `
397- a 大于 b
397+ a 小于 b
398398` ` `
399399
400400相信大家通过上面的示例就已经掌握了 shell 编程中的 if 条件语句。不过,还要提到的一点是,不同于我们常见的 Java 以及 PHP 中的 if 条件语句,shell if 条件语句中不能包含空语句也就是什么都不做的语句。
@@ -482,16 +482,20 @@ done
482482
483483` ` ` shell
484484#! /bin/bash
485- function (){
485+ hello (){
486486echo " 这是我的第一个 shell 函数!"
487487}
488- function
488+ echo " -----函数开始执行-----"
489+ hello
490+ echo " -----函数执行完毕-----"
489491` ` `
490492
491493输出结果:
492494
493495` ` `
496+ -----函数开始执行-----
494497这是我的第一个 shell 函数!
498+ -----函数执行完毕-----
495499` ` `
496500
497501
You can’t perform that action at this time.
0 commit comments