我有以下简单的 bash 脚本。由于某种原因,它总是返回 true。
#!/bin/bash
service=hhvm
status=($(ps -ef | grep -v grep | grep $service | wc -l))
if [[ $status -eq 0 ]]; then
echo "starting $service"
service hhvm start
else
echo "$service running"
fi
答案1
最终有效的脚本。在聊天中
#!/bin/bash
service=hhvm
if ! (($(ps -ef | grep -v "grep"| grep "$service" | wc -l))) ; then
echo "starting $service"
service hhvm start
else
echo "$service is running"
fi
答案2
foo=3
if [[ $foo -eq 0 ]]; then # -eq: equal
echo "foo equals 0"
else
echo "foo is not equal to 0"
fi