tldr/pages/common/test.md

26 lines
597 B
Markdown
Raw Normal View History

2015-12-12 22:08:54 +00:00
# test
> 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>.
2015-12-12 22:08:54 +00:00
- Test if a given variable is equal to a given string:
2015-12-12 22:08:54 +00:00
`test "{{$MY_VAR}}" == "{{/bin/zsh}}"`
2015-12-12 22:08:54 +00:00
- Test if a given variable is empty:
2015-12-12 22:08:54 +00:00
`test -z "{{$GIT_BRANCH}}"`
2015-12-12 22:08:54 +00:00
- Test if a file exists:
2015-12-12 22:08:54 +00:00
`test -f "{{path/to/file_or_directory}}"`
2015-12-12 22:08:54 +00:00
- Test if a directory does not exist:
2015-12-12 22:08:54 +00:00
`test ! -d "{{path/to/directory}}"`
2015-12-12 22:08:54 +00:00
- If-else statement:
2015-12-12 22:08:54 +00:00
`test {{condition}} && {{echo "true"}} || {{echo "false"}}`