2021-03-10 19:24:11 +00:00
|
|
|
# [
|
|
|
|
|
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>.
|
2021-03-10 19:24:11 +00:00
|
|
|
|
|
|
|
- Test if a given variable is equal to a given string:
|
|
|
|
|
2021-04-30 14:01:31 +01:00
|
|
|
`[ "{{$VARIABLE}}" == "{{/bin/zsh}}" ]`
|
2021-03-10 19:24:11 +00:00
|
|
|
|
|
|
|
- Test if a given variable is empty:
|
|
|
|
|
|
|
|
`[ -z "{{$GIT_BRANCH}}" ]`
|
|
|
|
|
|
|
|
- Test if a file exists:
|
|
|
|
|
2021-04-30 14:01:31 +01:00
|
|
|
`[ -f "{{path/to/file}}" ]`
|
2021-03-10 19:24:11 +00:00
|
|
|
|
|
|
|
- Test if a directory does not exist:
|
|
|
|
|
|
|
|
`[ ! -d "{{path/to/directory}}" ]`
|
|
|
|
|
|
|
|
- If-else statement:
|
|
|
|
|
|
|
|
`[ {{condition}} ] && {{echo "true"}} || {{echo "false"}}`
|