bash script conditions

https://dev.to/zakiarsyad/bash-script-conditions-1ano

Basic usage of if statement in bash scripting

if [ CONDITION ]; then FIRST_COMMANDS
elif [ CONDITION ]; then SECOND_COMMANDS
else THRID_COMMANDS
fi

There are three syntaxes for define the condition

Single-Bracket

Support 3 types of conditions

File-based condition

String-based condition

Arithmetic condition

Double-bracket

This is the enhanced version of single-bracket. All features in single-bracket syntax are compatible here. We can start using this syntax.

The differences :

Double-parenthesis

This is another syntax for arithmetic condition

We also can quickly test a condition like this

# using &&
[ $foo == "bar" ] && echo true

# using ||
[ $foo == "bar" ] || echo true

tags: #terminal

â­