tldr/pages/common/test.md

25 lines
423 B
Markdown
Raw Normal View History

2015-12-12 22:08:54 +00:00
# test
> Evaluate condition.
> If it is true, returns 0 exit status, otherwise returns 1.
- Test if given variable is equal to given string:
2015-12-12 22:08:54 +00:00
`test $MY_VAR == '/bin/zsh'`
- Test if given variable is empty:
2015-12-12 22:08:54 +00:00
`test -z $GIT_BRANCH`
- Test if file exists:
2015-12-12 22:08:54 +00:00
`test -e {{filename}}`
- Test if directory not exists:
2015-12-12 22:08:54 +00:00
`test ! -d {{path/to/directory}}`
- If-else statement:
2015-12-12 22:08:54 +00:00
`test {{condition}} && echo "true" || echo "false"`