Reputation: 533
how can I get status from command, which is assigned into variable?
For example:
#! /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
Upvotes: 3
Views: 175
Reputation: 836
How about this:
PID=($(pidof bash))
if [[ ${#PID[@]} -gt 0 ]]; then
echo "status OK"
else
echo "status not OK"
fi
Upvotes: 2