-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
### SHELL脚本参数 | ||
|
||
#### 位置参数 | ||
|
||
脚本通过位置参数来获取命令行中的参数。位置参数通过标准数字表示,例如`$0`代表脚本名称,`$1`代表第一个参数,`$2`代表第二个参数,依此类推。 | ||
|
||
#### 参数计数 | ||
|
||
使用`$#`可以测试执行脚本时包含的命令行参数个数。如果无参数,`$#`为0。 | ||
|
||
#### 获取所有数据: | ||
|
||
使用`$*`可以将命令行中提供的所有参数作为一个单词处理,它将多个参数看成一个参数。使用`$@`则将命令行中提供的所有参数作为同一个字符串中的多个单词处理。 | ||
|
||
#### 移位: | ||
|
||
使用`shift`命令可以改变命令行参数的相对位置。默认为每个参数变量左移一个位置,`$0`不变。 | ||
|
||
#### 处理选项: | ||
|
||
选项是由破折号引导的单个字母,用于更改命令的行为。例如,`-n`参数可以用来检查参数是否存在。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters