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