Files
tldr/pages.zh/common/[.md

33 lines
847 B
Markdown
Raw Permalink 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>。
- 测试给定变量是否等于/不等于指定字符串:
`[ "${{variable}}" {{=|!=}} "{{string}}" ]`
- 测试给定变量是否[等于]/[不]等于/[大于]/[小于]/[大于或等于]/[小于或等于]指定数字:
`[ "${{variable}}" -{{eq|ne|gt|lt|ge|le}} {{integer}} ]`
- 测试指定变量是否具有[非]空值:
`[ -n "${{variable}}" ]`
- 测试指定变量是否具有空值:
`[ -z "${{variable}}" ]`
- 测试指定[文件]是否存在:
`[ -f {{path/to/file}} ]`
- 测试指定[目录]是否存在:
`[ -d {{path/to/directory}} ]`
- 测试指定文件或目录[是否]存在:
`[ -e {{path/to/file_or_directory}} ]`