Trying to write a bash script to install and configure samba. Have added a control statement to check if samba is already installed. This takes dpkg output and pipes it into grep and checks if output contains "Status: install ok installed". When output matches the statement works correctly and prints "INFO: $package already installed", but when it doesn't match it outputs dpkg response along with running else block. How do I suppress the output of dpkg when it is unable to match?
#!/bin/bash
package="samba"
if dpkg -s "$package" | grep -Fxq "Status: install ok installed"
then
echo "INFO: $package already installed"
else
echo "[x] installing $package"
sudo apt update
echo ""
sudo apt install samba
fi
output (else):
dpkg-query: package 'samba' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files.
[x] installing samba
ouput(then)
INFO: unzip already installed