Files
tldr/pages.zh/common/[.md
Gabe Livengood 9d865abee1 test: Use POSIX-compliant example for equals comparison (#11728)
* [: use posix-compliant example for equals comparison

the previous example worked fine for bash, but some
other shells (zsh, in my case) will not work when
using "==" for comparison. the posix spec only requires
"=", so I think it makes a little more sense to use
that in the example.

* test: use posix-compliant example for equals comparison

the previous example worked fine for bash, but some
other shells (zsh, in my case) will not work when
using "==" for comparison. the posix spec only requires
"=", so I think it makes a little more sense to use
that in the example.
2023-12-14 20:31:13 +05:30

34 lines
853 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# [
> 检查文件类型,比较数值。
> 如果条件计算结果为真返回 0如果计算结果为假返回 1。
> 更多信息:<https://www.gnu.org/software/bash/manual/bash.html#index-test>.
- 测试一个给定的变量是否等于/不等于指定的字符串:
`[ "${{变量}}" {{=|!=}} "{{字符串}}" ]`
- 测试一个给定的变量是否等于/不等于/大于/小于/大于等于/小于等于指定的数字:
`[ "${{变量}}" -{{eq|ne|gt|lt|ge|le}} {{数字}} ]`
- 测试指定的变量的值是否非空:
`[ -n "${{变量}}" ]`
- 测试指定变量的值是否为空:
`[ -z "${{变量}}" ]`
- 测试指定文件是否存在:
`[ -f {{路径/到/文件}} ]`
- 测试指定目录是否存在:
`[ -d {{路径/到/目录}} ]`
- 测试指定文件或目录是否存在:
`[ -e {{路径/到/文件或目录}} ]`