tldr/pages.zh/common/[.md

26 lines
522 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# [
> 评估条件。
> 如果条件评估为真返回 0如果评估为假返回 1.
> 更多信息:<https://www.gnu.org/software/coreutils/test>.
- 测试给定变量是否与给定字符串相同:
`[ "{{$VARIABLE}}" == "{{/bin/zsh}}" ]`
- 测试给定变量是否为空值:
`[ -z "{{$GIT_BRANCH}}" ]`
- 测试某个文件是否存在:
`[ -f "{{文件}}" ]`
- 测试某个目录是否存在:
`[ ! -d "{{目录}}" ]`
- If-else 语句:
`[ {{条件语句}} ] && {{echo "true"}} || {{echo "false"}}`