如何从命令中获取状态,该命令被分配到变量中?
例如:
#! /bin/bash
### GET PID
GETPID=$(ps aux | grep "bash" | grep -v "grep" | awk '{print $2 }')
if [ "$?" = "0" ]; then
echo "status OK"
else
echo "status NOT OK"
fi
答案 0 :(得分:2)
这个怎么样:
PID=($(pidof bash))
if [[ ${#PID[@]} -gt 0 ]]; then
echo "status OK"
else
echo "status not OK"
fi