Using `{{command}} && {{command1}} || {{command2}}` does not actually
work like if, and it's misleading to teach that to users. The difference
is that in the above construct, command2 gets executed if command1
fails, which does not happen in a real if as in `if {{command}}; then
{{command1}}; else {{command2}}; fi`
28 lines
593 B
Markdown
28 lines
593 B
Markdown
# if
|
|
|
|
> Simple shell conditional.
|
|
|
|
- Echo a different thing depending on a command's success:
|
|
|
|
`if {{command}}; then echo "success"; else echo "failure"; fi`
|
|
|
|
- Full if syntax:
|
|
|
|
`if {{condition}}; then echo "true"; else echo "false"; fi`
|
|
|
|
- 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`
|