bash script if or code example
Example 1: bash or
if [ "$1" = "a.txt" ] || [ "$2" = "c.txt" ]; then
fi
Example 2: bash if statement
and - &&
or - ||
if [ -r $1 ] && [ -s $1 ]
then
echo This file is useful.
fi
if [ $USER == 'bob' ] || [ $USER == 'andy' ]
then
ls -alh
else
ls
fi
Example 3: if and if bash
if [ "${STATUS}" != 200 ] && [ "${STRING}" != "${VALUE}" ]; then
Example 4: bash if
#!/bin/bash
foo="qux"
bar="qux"
if [ "$foo" = "$bar" ]; then
echo "The strings are equal."
else
echo "The strings aren't equal."
fi
Example 5: codition in bash
[ $(( 2 + 2 )) -eq '4' ] && echo "yes"
if [ $(( 2 + 2 )) -eq '4' ]
then
echo "yess"
fi