Will Ashworth
Will Ashworth

Reputation: 1088

Bash script not behaving like I'd expect

I've poured over question after question searching here and on Google, but something in my syntax is messed up. Any assistance is appreciated.

Basically I've got another function that sets the load and threshold, as well as $FORCE variable. The script needs to do the "stuff" if it meets either the first or the second condition. The variables have been set correctly, which I've confirmed via echo in the script while debugging.

if ([ $LOAD -ge "$THRESH" ] || [ $FORCE=1 ]);
then
    # do some other stuff
fi

From what I can see, my spacing of the brackets around the conditions are correct. They no longer produce bash [: missing]'` errors like they were.

The script runs fine, except for one issue...it runs no matter what. It's like it's completely ignoring the [ $FORCE=1 ] part, even though I can see that $FORCE is in fact actually 0.

Should I be using single quotes or some other method?

Upvotes: 1

Views: 55

Answers (1)

twin
twin

Reputation: 1669

Try putting spaces around =:

if ([ $LOAD -ge "$THRESH" ] || [ $FORCE = 1 ]);
then
    # do some other stuff
fi

Upvotes: 2

Related Questions