我正在尝试使用Shell脚本将/etc/sysctl.conf
的实际值与建议值进行比较。这两个值相同,但是if
语句正在执行,而不是else
。
shmmnireq=4096
shmmni=$(grep "shmmni" /etc/sysctl.conf | cut -d " " -f3)
echo $shmmnireq
echo $shmmni
if [[ $shmmnireq == $shmmni ]];then
echo "shmmni is configured"
else
echo "shmmni is not configured"
fi
输出:
4096
4096
shmmni is not configured
答案 0 :(得分:1)
尝试一下-
#!/bin/bash
shmmnireq=4096
shmmni=$(grep "shmmni" /etc/sysctl.conf | cut -d " " -f3)
echo $shmmnireq
echo $shmmni
if [ "$shmmnireq" -eq "$shmmni" ];then
echo "shmmni is configured"
else
echo "shmmni is not configured"
fi
答案 1 :(得分:0)
我已经测试了以下代码。这将起作用:
#!/bin/bash
shmmnireq=4096
shmmni=$(grep "shmmni" /etc/sysctl.conf | cut -d " " -f3)
echo $shmmnireq
echo $shmmni
if [[ ${shmmnireq} -eq ${shmmni} ]]
then
echo "shmmni is configured"
else
echo "shmmni is not configured"
fi