2016-01-05 18:47:12 +00:00
|
|
|
# if
|
|
|
|
|
2016-01-13 11:04:46 +00:00
|
|
|
> Simple shell conditional.
|
2016-01-05 18:47:12 +00:00
|
|
|
|
2016-01-13 11:04:46 +00:00
|
|
|
- Echo a different thing depending on a command's success:
|
2016-01-05 18:47:12 +00:00
|
|
|
|
|
|
|
`{{command}} && echo "success" || echo "failure"`
|
|
|
|
|
2016-01-13 11:04:46 +00:00
|
|
|
- Full if syntax:
|
2016-01-05 18:47:12 +00:00
|
|
|
|
|
|
|
`if {{condition}}; then echo "true"; else echo "false"; fi`
|
2019-08-18 18:05:41 +01:00
|
|
|
|
|
|
|
- List available if conditions:
|
|
|
|
|
|
|
|
`help test`
|
|
|
|
|
|
|
|
- Test if a given variable is empty:
|
|
|
|
|
|
|
|
`if [[ -z $GIT_BRANCH ]]; then echo "true"; else echo "false"; fi`
|
|
|
|
|
|
|
|
- Test if a file exists:
|
|
|
|
|
|
|
|
`if [[ -e {{filename}} ]]; then echo "true"; else echo "false"; fi`
|
|
|
|
|
|
|
|
- If directory not exists:
|
|
|
|
|
|
|
|
`if [[ ! -d {{path/to/directory}} ]]; then echo "true"; else echo "false"; fi`
|