What is the syntax of if loop in bash

The 'if statement' executes a statement if a specified condition is true. If the condition is false, another statement can be executed.

The syntaxes of different types of 'if statements' in bash are given below.

if loop normal case

if [ condition ]
then
else
fi

if loop OR case

if [ condition1 ] || [ condition2 ]
then
else
fi

if loop AND case

if [ condition1 ] && [ condition2 ]
then
else
fi

if loop OR+AND case

if [ condition1 ] || [[ condition2 && condition3 ]]
then
else
fi

Leave a Reply

Your email address will not be published. Required fields are marked *