if Command Examples

Performs conditional processing in shell scripts. See also: test, [. More information: https://www.gnu.org/software/bash/manual/bash.html#Conditional-Constructs.

if {{condition_command}}; then {{echo "Condition is true"}}; fi

if ! {{condition_command}}; then {{echo "Condition is true"}}; fi

if {{condition_command}}; then {{echo "Condition is true"}}; else {{echo "Condition is false"}}; fi

if [[ -f {{path/to/file}} ]]; then {{echo "Condition is true"}}; fi

if [[ -d {{path/to/directory}} ]]; then {{echo "Condition is true"}}; fi

if [[ -e {{path/to/file_or_directory}} ]]; then {{echo "Condition is true"}}; fi

if [[ -n "${{variable}}" ]]; then {{echo "Condition is true"}}; fi

man [