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 # 遍历数组,数组元素为空,没
272
272
> 说明:图片来自《菜鸟教程》
273
273
274
274
Shell 编程支持下面几种运算符
275
-
275
+
276
276
- 算数运算符
277
277
- 关系运算符
278
278
- 布尔运算符
@@ -380,10 +380,10 @@ a 不等于 b
380
380
#! /bin/bash
381
381
a=3;
382
382
b=9;
383
- if [ $a = $b ]
383
+ if [ $a -eq $b ]
384
384
then
385
385
echo " a 等于 b"
386
- elif [ $a > $b ]
386
+ elif [ $a -gt $b ]
387
387
then
388
388
echo " a 大于 b"
389
389
else
394
394
输出结果:
395
395
396
396
` ` `
397
- a 大于 b
397
+ a 小于 b
398
398
` ` `
399
399
400
400
相信大家通过上面的示例就已经掌握了 shell 编程中的 if 条件语句。不过,还要提到的一点是,不同于我们常见的 Java 以及 PHP 中的 if 条件语句,shell if 条件语句中不能包含空语句也就是什么都不做的语句。
@@ -482,16 +482,20 @@ done
482
482
483
483
` ` ` shell
484
484
#! /bin/bash
485
- function (){
485
+ hello (){
486
486
echo " 这是我的第一个 shell 函数!"
487
487
}
488
- function
488
+ echo " -----函数开始执行-----"
489
+ hello
490
+ echo " -----函数执行完毕-----"
489
491
` ` `
490
492
491
493
输出结果:
492
494
493
495
` ` `
496
+ -----函数开始执行-----
494
497
这是我的第一个 shell 函数!
498
+ -----函数执行完毕-----
495
499
` ` `
496
500
497
501
You can’t perform that action at this time.
0 commit comments