How would you create an if statement that contains an or operator to evaluate the first parameter passed in?
I've copied examples straight from the links at the bottom with no luck. I've also copied other examples I've found online unsuccessfully.
# not working
if [ "$1" = "restart" || "$1" = "reload"]; then
echo "you passed in $1"
exit 3
fi
# not working
if [[ "$1" = "restart" || "$1" = "reload"]]; then
echo "you passed in $1"
exit 3
# not working
if [ $1 = "restart" || $1 = "reload"]; then
echo "you passed in $1"
exit 3
fi
# not working
if [ $1 == "restart" || $1 == "reload"]; then
echo "you passed in $1"
exit 3
fi
# not working
if [ $1 == "restart" || $1 == "reload"]; then
echo "you passed in $1"
exit 3
fi
# not working
if [ "$1" = "restart" || "$1" = "reload" ]; then
echo "you passed in $1"
exit 3
fi
# not working
if [ "$1" == "restart"] || [ "$1" == "reload" ]; then
echo "you passed in $1"
exit 3
fi
plus every other syntax I can find....
I am given one of the following errors
/etc/init.d/gitlab: 192: [: =: unexpected operator
or
/etc/init.d/gitlab: 192: [: missing ]
or
/etc/init.d/gitlab: 194: [: missing ]
/etc/init.d/gitlab: 194: [: ==: unexpected operator
Resources:
http://tldp.org/LDP/abs/html/comparison-ops.html
How to do a logical OR operation in Shell Scripting
http://www.thegeekstuff.com/2010/06/bash-if-statement-examples/