2015-12-12 22:08:54 +00:00
|
|
|
# test
|
|
|
|
|
2021-11-07 00:57:43 +00:00
|
|
|
> Check file types and compare values.
|
2021-03-10 19:24:11 +00:00
|
|
|
> Returns 0 if the condition evaluates to true, 1 if it evaluates to false.
|
2021-04-01 16:54:26 +01:00
|
|
|
> More information: <https://www.gnu.org/software/coreutils/test>.
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
- Test if a given variable is equal to a given string:
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2023-12-14 15:01:13 +00:00
|
|
|
`test "{{$MY_VAR}}" = "{{/bin/zsh}}"`
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
- Test if a given variable is empty:
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
`test -z "{{$GIT_BRANCH}}"`
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
- Test if a file exists:
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
`test -f "{{path/to/file_or_directory}}"`
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
- Test if a directory does not exist:
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
`test ! -d "{{path/to/directory}}"`
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2022-10-04 10:49:21 +01:00
|
|
|
- If A is true, then do B, or C in the case of an error (notice that C may run even if A fails):
|
2015-12-12 22:08:54 +00:00
|
|
|
|
2021-03-10 19:24:11 +00:00
|
|
|
`test {{condition}} && {{echo "true"}} || {{echo "false"}}`
|