|
Title: Bourne/bash shell scripts: if statement syntax Post by: Mark David on March 16, 2007, 01:33:58 PM Bourne/bash shell scripts: if statement syntax
Conditional expressions give programs life. The ability to branch makes shell scripts powerful. This recipe shows the basic if then else structure for sh, ksh, bash, zsh, etc. Code: if [ condition_A ] then code to run if condition_A true elif [ condition_B ] then code to run if condition_A false and condition_B true else code to run if both conditions false fi Multiple elif blocks can be strung together to make an elaborate set of conditional responses. |