jore
jore

Reputation: 1

Bash script produces error using if condition

I have a problem with if in bash script. I've written the following if condition but it produces an error:

if [[ "$capacity" != *10 && "$capacity" != *20  ]] || [[ "$capacity" != *80 && "$capacity" != *100 ]]; then

Simply, I want to compare (two values not equals to) || (two values not equals to) condition using or operator

Upvotes: 0

Views: 63

Answers (1)

that other guy
that other guy

Reputation: 123410

I took your line and added enough additional lines to make it a Minimal, Complete, and Verifiable example:

#!/bin/bash
capacity=55

if [[ "$capacity" != *10 && "$capacity" != *20  ]] || [[ "$capacity" != *80 && "$capacity" != *100 ]]; then
  echo "match"
fi

Then I ran it like this:

$ chmod +x ./myscript
$ ./myscript
match

It wrote "match", exactly as I expected.

Will you please do the same thing?

  1. Add enough lines so that I can run your code on my machine
  2. Show how you run it and what it outputs
  3. Explain why this is different from what you expected

Upvotes: 1

Related Questions