This document provides an overview of conditional statements and tests in Bash scripts. It describes the if/elif/else conditional statement for executing commands based on test expressions. It also covers the case statement for pattern matching. Various test expressions are listed for checking string/integer comparisons and file properties. Operators like && and || allow combining multiple test expressions, and commands like echo and read are referenced. Finally, it touches on single and double quotes and how they treat variable expansion.
This document provides an overview of conditional statements and tests in Bash scripts. It describes the if/elif/else conditional statement for executing commands based on test expressions. It also covers the case statement for pattern matching. Various test expressions are listed for checking string/integer comparisons and file properties. Operators like && and || allow combining multiple test expressions, and commands like echo and read are referenced. Finally, it touches on single and double quotes and how they treat variable expansion.
This document provides an overview of conditional statements and tests in Bash scripts. It describes the if/elif/else conditional statement for executing commands based on test expressions. It also covers the case statement for pattern matching. Various test expressions are listed for checking string/integer comparisons and file properties. Operators like && and || allow combining multiple test expressions, and commands like echo and read are referenced. Finally, it touches on single and double quotes and how they treat variable expansion.
if <test-expression>; then <commands> elif <test-expression>; then <commands> else <commands> fi
case $var in <pattern>) <commands>;; *) <commands>;; esac
[ -n $var ] //True if the length of $var is greater than zero
[ -z $var ] //True if $var is empty [ string1 (=|!=) string2 ] [ int1 -(eq|neq|gt|lt|ge|le) int2 ] [ -(d|f) FILE ] //-d: true if FILE exists and a directory, -f: true if FILE exists and a file (not a device)
* &&, || may be used between multiple <test-expression>
echo, read command single quote (') preserves literal value inside, (") does not preserve all things (for example variable will be expanded)