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.
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.






Add New Comment
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Add New Comment