bash input parameter logic
You can achieve the same but simpler if you reorder the validation steps.

If there are two arguments and both are test, that's invalid:

[ "$1" = test ] &amp;&amp; [ "$2" = test ] &amp;&amp; invalid


Where invalid is a helper function:

invalid() {
    echo not valid
    exit 1
}


If the second argument is test, then enable testing,
or else if the first argument is test then enable testing and shift the arguments:

if [ "$2" = test ]; then
    echo enable testing
elif [ "$1" = test ]; then
    echo enable testing
    shift
fi


At this point, the should be 0 or 1 arguments, not more.
That was a missing validation step in the original code:

[ $# -le 1 ] || invalid


If we reach this point,
there must be 0 or 1 arguments.
The original case statement can come here as before, without any further if statements. It can use the invalid helper function in the invalid case.