I need to check if a specific package is installed on a machine from within a Bash script.
I found something like that but I don't know how use it correctly.
dpkg -l | grep "ansible" | awk '{print $2}'
if [$? -eq 0]; then
echo OK
else
echo FAIL
fi
I need check, if command dpkg -l | grep "ansible" | awk '{print $2}'
return me word "Ansible" then echo OK, else echo FAIL.
@EDIT
I think better will be command
dpkg -l | grep "ansible" | awk '{print $2}'
so this command return me two words:
ansible
ansible_lint
How should I use this bash script? If I doing something like that:
ansible = $?
if [$? -eq 0]; then
echo OK
else
echo FAIL
fi
that's not work, but I'm sure I doing that wrong. How can I read result from dpkg -l | grep "ansible" | awk '{print $2}' command and if I get word "ansible" script will print OK, if not print FAIL.