linux script if code example
Example 1: 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 2: if and if bash
if [ "${STATUS}" != 200 ] && [ "${STRING}" != "${VALUE}" ]; then
Example 3: 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 4: ash if statment
if [ "$USER" == "Adam" ]
then
echo "User is Adam"
else
echo "User is not Adam"
fi