简体   繁体   English

Bash脚本的行为不像我期望的那样

[英]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. 我在这里和Google上搜索了一个又一个的问题,但是我的语法有些混乱。 Any assistance is appreciated. 任何帮助表示赞赏。

Basically I've got another function that sets the load and threshold, as well as $FORCE variable. 基本上,我有另一个函数来设置负载和阈值以及$ FORCE变量。 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. 变量已正确设置,调试时已通过脚本中的echo确认了这些变量。

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. 它们不再像以前那样产生bash [: missing ]'`错误。

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. 就像我完全忽略了[ $FORCE=1 ]部分一样,尽管我可以看到$FORCE实际上是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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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