差别
这里会显示出您选择的修订版和当前版本之间的差别。
后一修订版 | 前一修订版 | ||
blog:shell:03_shell_cond_and_branch [2022/01/09 17:21] – 创建 - 外部编辑 127.0.0.1 | blog:shell:03_shell_cond_and_branch [2022/08/26 11:31] (当前版本) – caodan | ||
---|---|---|---|
行 2: | 行 2: | ||
## 条件判断 | ## 条件判断 | ||
+ | |||
1. 数字的判断 | 1. 数字的判断 | ||
- | | + | |
- | ``` | + | ``` |
- | [ int1 -eq int2 ] 两数相等为真 | + | [ int1 -eq int2 ] 两数相等为真 |
- | [ int1 -ne int2 ] 两数不等为真 | + | [ int1 -ne int2 ] 两数不等为真 |
- | [ int1 -gt int2 ] int1大于int2为真 | + | [ int1 -gt int2 ] int1大于int2为真 |
- | [ int1 -ge int2 ] int1大于等于int2为真 | + | [ int1 -ge int2 ] int1大于等于int2为真 |
- | [ int1 -lt int2 ] int1小于int2为真 | + | [ int1 -lt int2 ] int1小于int2为真 |
- | [ int1 -le int2 ] int1小于等于int2为真 | + | [ int1 -le int2 ] int1小于等于int2为真 |
- | ``` | + | ``` |
- | + | ||
2. 文件的判断 | 2. 文件的判断 | ||
- | | + | |
- | ``` | + | ``` |
- | [ -r file ] 用户可读为真 | + | [ -r file ] 用户可读为真 |
- | [ -w file ] 用户可写为真 | + | [ -w file ] 用户可写为真 |
- | [ -x file ] 用户可执行为真 | + | [ -x file ] 用户可执行为真 |
- | [ -f file ] 文件为正规文件为真 | + | [ -f file ] 文件为正规文件为真 |
- | [ -d file ] 文件为目录为真 ,即检测目录是否存在。 | + | [ -d file ] 文件为目录为真 ,即检测目录是否存在。 |
- | [ -c file ] 文件为字符设备文件为真 | + | [ -c file ] 文件为字符设备文件为真 |
- | [ -b file ] 文件为块设备文件为真 | + | [ -b file ] 文件为块设备文件为真 |
- | [ -s file ] 文件大小非0时为真 | + | [ -s file ] 文件大小非0时为真 |
- | [ -t file ] 当文件描述符(默认为1)指定的设备为终端时为真 | + | [ -t file ] 当文件描述符(默认为1)指定的设备为终端时为真 |
- | [ -e file ] 如果文件存在,则为真。 | + | [ -e file ] 如果文件存在,则为真。 |
- | [ -L file ] 如果文件为符号链接, 则为真。 | + | [ -L file ] 如果文件为符号链接, 则为真。 |
- | ``` | + | ``` |
3. 逻辑判断 | 3. 逻辑判断 | ||
- | | + | ``` |
- | [ condition -a condition ] 与 | + | [ condition -a condition ] 与 |
- | [ condition -o condition ] 或 | + | [ condition -o condition ] 或 |
- | [ condition ! condition ] 非 | + | [ condition ! condition ] 非 |
- | ``` | + | ``` |
4. 字符串判断 | 4. 字符串判断 |