I like to check whether several packages are installed or not on Debian/Ubuntu Here is my attempt at a script to do this:
query=`dpkg-query -W -f '${Status}'`
ok="install ok"
if ! [ `$query` curl == "$ok" ] ;then
apt-get -y -qq install curl >> /dev/null 2>&1
fi
The result is
Install: target Installed is not a directory
but it should be what you can see in the second variable. I have a headache, npw because I can't find out the right way to handle this.
apt-get --assume-yes --quiet=2
– Fabian Jan 24 '15 at 15:33apt-get install a b c
? Or do you really care whether they were installed before? – Fabian Jan 24 '15 at 15:41dpkg-query
isinstall ok installed
notinstall ok
. Second:query
should be function altogether with check and return exit code but not variable. – Costas Jan 24 '15 at 15:41apt-cache policy pkgname1 pkgname2
will show you whether your packages are installed, if so what versions are installed,and what other versions are available, if any, in a compact format. It works for me. – Faheem Mitha Jan 24 '15 at 16:31