I have a script where I pass a string variable. Now I would like to check the value of the variable passed like this:
- Check if it's not null
- Check if is "Test1"
- Check if is "Test2"
I wrote this: #!/bin/bash
if [[ "$1" == "" || "$1" != "Test1" || "$1" != "Test2" ]]; then
echo "ERROR: no argument or bad argument passed. Only Test1 or Test2 is accepted"
exit 2
else
echo "ok good value"
exit 0
fi
but when I try the script (./script.sh Test1 or ./script.sh Test2) I receive always:
ERROR: no argument or bad argument passed. Only Test1 or Test2 is accepted
Test1OR argument is NOT Test2 is always going to be true.