test, [: add page, improve examples (#5205)

This commit is contained in:
Pierre Rudloff
2021-03-10 20:24:11 +01:00
committed by GitHub
parent 9a80a729c3
commit 3f25e8f0a0
2 changed files with 36 additions and 10 deletions

25
pages/common/[.md Normal file
View File

@@ -0,0 +1,25 @@
# [
> Evaluate condition.
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false.
> More information: <https://www.gnu.org/software/coreutils/manual/html_node/test-invocation.html>.
- 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"}}`