Creating a bash script and using the if statement, how do I execute a command based on a system status?
if a specific system status is enabled do something, else do something different?
I give you a real example. Let's say, for example, I want to execute some commands based on the Mac OS X Gatekeeper status of the system.
Example: the following command line on your Mac OS X spctl --status
will give you 2 possible output: assessments disabled
or assessments enabled
.
Can I do something like that below? Or there is a cleaner and more efficient way to do it? Thank you
#!/usr/bin/env bash
gatekeeper_status=$(spctl --status)
if [[ ${gatekeeper_status} == "assessments enabled" ]]
then
echo "Gatekeeper is enabled do some stuff"
else
echo "Gatekeeper is disabled do some stuff"
fi