декларация баш if
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
в противен случай, ако синтаксис на оператор баш
#!/bin/bash
read -p "Enter your marks: " marks
if [ $marks -ge 80 ]
then
echo "Very Good"
elif [ $marks -ge 50 ]
then
echo "Good"
elif [ $marks -ge 33 ]
then
echo "Just Satisfactory"
else
echo "Not OK"
fi
ако и ако един удар
if [ "${STATUS}" != 200 ] && [ "${STRING}" != "${VALUE}" ]; then
баш, ако
#!/bin/bash
foo="qux"
bar="qux"
if [ "$foo" = "$bar" ]; then
echo "The strings are equal."
else
echo "The strings aren't equal."
fi
ако все още скрипт на обвивката bash
if [[ some condition ]]; then
do_this
elif [[ another condition ]]; then
do_that_a
elif [[ yet another condition]]; then
do_that_b
else
do_that_default_thing
fi