简体   繁体   中英

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?

Try putting spaces around = :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM