Damon
Damon

Reputation: 127

Bash comparison of two strings

I'm probably having a big logical mind barrier right now and i just don't get it.. I hope someone can help me.

I'm writing a script with arguments and the first argument needs to be "activate" or "deactivate" so i wrote this:

if [ "$1" != "activate" ] || [ "$1" != "deactivate" ]; then
   echo $1
   exit 1
fi
echo "Hello the first argument is $1"

so if i run now 'myscript.sh activate' the output is:

user@host$ ./myscript.sh activate
activate

but the output should be "Hello the first argument is activate"...

Can someone explain me what i'm doing wrong or what i need to change?

Thanks

Upvotes: 0

Views: 39

Answers (1)

Cyrus
Cyrus

Reputation: 88601

I suggest to use:

if [ "$1" != "activate" ] && [ "$1" != "deactivate" ]; then

Upvotes: 2

Related Questions