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

25 lines
662 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/coreutils/test>。
- 测试给定变量是否等于给定字符串:
`test "{{$MY_VAR}}" = "{{/bin/zsh}}"`
- 测试给定变量是否为空:
`test -z "{{$GIT_BRANCH}}"`
- 测试文件是否存在:
`test -f "{{path/to/file_or_directory}}"`
- 测试目录是否不存在:
`test ! -d "{{path/to/directory}}"`
- 如果A为真则执行B或在错误情况下执行C注意即使A失败C也可能会执行
`test {{condition}} && {{echo "true"}} || {{echo "false"}}`