I am basically trying to see if a service is running and, if not, then start the service. Everything seems to work fine if the service is not running; however, when the service is running, the exact same if condition complains about syntax issues. Here's my example below:
# systemctl status [email protected]
[email protected] - Advanced key-value store (openvas)
Loaded: loaded (/usr/lib/systemd/system/[email protected], disabled)
Active: inactive (dead)
# if [ ! $(systemctl status [email protected] | grep -i "active: active") ]; then systemctl start [email protected]; fi
# systemctl status [email protected]
[email protected] - Advanced key-value store (openvas)
Loaded: loaded (/usr/lib/systemd/system/[email protected], disabled)
Active: active (running)
# if [ ! $(systemctl status [email protected] | grep -i "active: active") ]; then systemctl start [email protected]; fi
bash: [: active: binary operator expected
#
How is there a syntax issue all of a sudden if the same command is run before and has no problems?