mirror of https://github.com/CrimsonTome/tldr.git
26 lines
556 B
Markdown
26 lines
556 B
Markdown
# [
|
|
|
|
> Evaluate condition.
|
|
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false.
|
|
> More information: <https://www.gnu.org/software/coreutils/test>.
|
|
|
|
- Test if a given variable is equal to a given string:
|
|
|
|
`[ "{{$MY_VAR}}" == "{{/bin/zsh}}" ]`
|
|
|
|
- Test if a given variable is empty:
|
|
|
|
`[ -z "{{$GIT_BRANCH}}" ]`
|
|
|
|
- Test if a file exists:
|
|
|
|
`[ -f "{{path/to/file_or_directory}}" ]`
|
|
|
|
- Test if a directory does not exist:
|
|
|
|
`[ ! -d "{{path/to/directory}}" ]`
|
|
|
|
- If-else statement:
|
|
|
|
`[ {{condition}} ] && {{echo "true"}} || {{echo "false"}}`
|