this script is working properly
stat1=$(systemctl list-units --type=service | grep gravity | grep gcr | awk {'print $1'} | xargs systemctl status | grep Active | awk {'print $2'})
echo "$stat1"
if [ $stat1 == 'active' ]
then
echo " >> Gravity service is running ..."
else
echo " >> Gravity service not running ..."
fi
this one isn't
stat2=$(gravity status | grep status | awk {'print $3'})
echo "$stat2"
if [ $stat2 == 'active' ]
then
echo " >> Gravity service is running ..."
else
echo " >> Gravity service not running ..."
fi
the only difference between them is the input for stat variable on this script is white, and the other one is green. i also tried using if [[ ]] , and changed '' to "" for the stat var , none of this worked Please help me understand how to make it work.
tried this :
the result remains the same.
[
is a command,]
is its last argument. The command does not change the way the arguments are parsed (for comparison: it's different with[[
which is a shell keyword). This means in general you should double-quote. You got away this time, still good practice is a virtue and it's way easier always to quote than to wonder each time if it's safe not to quote. – Kamil Maciorowski Jan 13 '22 at 21:27