Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions 10. Shell 函数.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ echo "-----function start-----"
### 输出:
```
asa@asa-virtual-machine:~$ ./printf.sh
-----func start-----
This is my first shell func
-----func start-----
-----function start-----
This is my first shell function
-----function start-----
```
### 实例2(有return):
```
Expand Down Expand Up @@ -57,7 +57,7 @@ Input the first num1:
1
Input the second num2:
5
Two nums are 1 and 5 !
Two nums are 1 and 5
num1 + num2 = 6
```
函数返回值在调用该函数后通过 $? 来获得。
Expand All @@ -84,12 +84,12 @@ funWithParam 1 2 3 4 5 6 7 8 9 34 73
### 输出:
```
asa@asa-virtual-machine:~$ ./printf.sh
first param is 1
second param is 2
tenth param is 10
tenth param is 34
eleventh param is 73
Total count is 11
The first param is 1
The second param is 2
The tenth param is 10
The tenth param is 34
The eleventh param is 73
Total count is 11
A string of all params is 1 2 3 4 5 6 7 8 9 34 73
```
### 注意:
Expand All @@ -104,4 +104,4 @@ $10 不能获取第十个参数,获取第十个参数需要${10}。当n>=10时
|$!| 后台运行的最后一个进程的ID号|
|$@| 与$*相同,但是使用时加引号,并在引号中返回每个参数。|
|$-| 显示Shell使用的当前选项,与set命令功能相同。|
|$?| 显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误。|
|$?| 显示最后命令的退出状态。0表示没有错误,其他任何值表明有错误。|