如何从分配给变量的命令中获取状态?
例如:
#! /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
最佳答案
这个怎么样:
PID=($(pidof bash))
if [[ ${#PID[@]} -gt 0 ]]; then
echo "status OK"
else
echo "status not OK"
fi
关于bash - 命令返回数据到变量的返回状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31006952/