0

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

4
  • 3
    your 1st argument which is "activate" is certainly not equal to "deactivate". Which make the second comparison set to true. Remember you are using OR operator in between. Commented Nov 23, 2016 at 9:02
  • 1
    [ "$1" != "deactivate" ] is true. Commented Nov 23, 2016 at 9:02
  • yeah thanks, i think i got it now:) Commented Nov 23, 2016 at 9:06
  • i know, i wanted to do that but it said i need to wait a few minutes until i'm able to accept your answer. Commented Nov 23, 2016 at 9:19

1 Answer 1

2

I suggest to use:

if [ "$1" != "activate" ] && [ "$1" != "deactivate" ]; then
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.