Trying to comparisons with a variable against strings, i tried code as per the solution from https://unix.stackexchange.com/questions/67898/using-the-not-equal-operator-for-string-comparison
if [ "$ACTION" != "dry" ] && [ "$ACTION" != "prune" ]
then
echo "Invalid"
fi
This does not work for me, i get no error messages it's like it just skips the code block.
I have also tried like this as per answer here Bash if statement with multiple conditions
if [[ "$ACTION" != "dry" && "$ACTION" != "prune" ]]
then
echo "Invalid"
fi
This echoes "Invalid" if $ACTION is anything other than "dry", even if its "prune"
Any suggestions?
EDIT
Full code
OPTIND=1
while getopts "b:a:" option
do
case "${option}"
in
b) MERGE_BRANCH=${OPTARG};;
a) ACTION=${OPTARG};;
esac
done
if [[ "$ACTION" != "dry" && "$ACTION" != "prune" ]]
then
echo "Invalid"
fi
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
(( 1 <= ${#} )) || { echo "missing mandatory argument" 2>&1 ; exit 1; };