Shell/Bash script logical or boolean operators

Boolean AND:

&& or -a used to do boolean AND operations in bash/shell scripts.

To validate boolean AND condition there are two ways:

if [ $condition1 ] && [ $condition2 ]

You can also validate as

if [ $condition1 -a $condition2 ]

Boolean OR:

|| or -o used to do boolean OR operations in bash/shell scripts.

To validate boolean OR there are 2 ways:

if [ $condition1 ] || [ $condition2 ]

You can also validate boolean OR as

if [ $condition1 -o $condition2 ]

-Sany

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s