Files
tldr/pages.zh/common/[.md
2024-09-10 22:52:30 +02:00

34 lines
849 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://gnu.org/software/bash/manual/bash.html#index-test>.
- 测试一个给定的变量是否等于/不等于指定的字符串:
`[ "${{变量}}" {{=|!=}} "{{字符串}}" ]`
- 测试一个给定的变量是否等于/不等于/大于/小于/大于等于/小于等于指定的数字:
`[ "${{变量}}" -{{eq|ne|gt|lt|ge|le}} {{数字}} ]`
- 测试指定的变量的值是否非空:
`[ -n "${{变量}}" ]`
- 测试指定变量的值是否为空:
`[ -z "${{变量}}" ]`
- 测试指定文件是否存在:
`[ -f {{路径/到/文件}} ]`
- 测试指定目录是否存在:
`[ -d {{路径/到/目录}} ]`
- 测试指定文件或目录是否存在:
`[ -e {{路径/到/文件或目录}} ]`