If you split it up as suggested by astralc, you now invoke test/[…] with 3 arguments, and (due argument 2 being `=`) instruct it to test for equality between argument 1 and argument 3, which is probably what you want.
If you do not care to handle `failed` as a state, the following would be even more direct (no need for using test/[…] or launching a subshell):
if systemctl is-active --quiet cronie.service; then
# stop service here
else
# start service here
fi
--edit Ah, too slow, the second part is now a slight repetition of lambdarch's suggestion.
]]>if ! systemctl --quiet is-active cronie.cervice
#! /bin/bash
if [ "$(sudo systemctl is-active cronie.cervice)"="inactive" ];
then
sudo systemctl start cronie.service
echo "cronie started"
else
sudo systemctl stop cronie.service
echo "cronie stopped"
fi
if i run the script it only starts the service but will not stop it no matter what is-active says
I have tried a one-line version with the same problem.
thanks in advance.