use if else in bash code example
Example 1: if else statement example in shell script
if [ ... ]
then
# if-code
else
# else-code
fi
Example 2: bash if statement
and - &&
or - ||
# and example
if [ -r $1 ] && [ -s $1 ]
then
echo This file is useful.
fi
# or example
if [ $USER == 'bob' ] || [ $USER == 'andy' ]
then
ls -alh
else
ls
fi