我希望您能在Linux shell脚本中将一个变量与另一个变量减去一个常量进行比较。在cpp中,这看起来像这样:
在shell中,我尝试了以下操作:
我也尝试了:
没有一个版本是有效的。您如何正确编写这样的条件?
敬礼。
int index = x;
int max_num = y;
if (index < max_num - 1) {
// do whatever
} else {
// do something else
}
在shell中,我尝试了以下操作:
index=0
max_num=2
if [ $index -lt ($max_num - 1) ]; then
sleep 20
else
echo "NO SLEEP REQUIRED"
fi
我也尝试了:
if [ $index -lt ($max_num-1) ]; then
...
if [ $index -lt $max_num - 1 ]; then
...
if [ $index -lt $max_num-1 ]; then
...
没有一个版本是有效的。您如何正确编写这样的条件?
敬礼。