[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: scriptable way to list packages that are not installed



On 1/14/2018 7:28 AM, john doe wrote:
On 1/14/2018 4:52 AM, Vasyl Vavrychuk wrote:
I would like to list not installed packages in my script. Currently I do

     dpkg-query -W -f='${db:Status-Abbrev}${binary:Package}\n'
$PACKAGES | grep -v "^ii" | awk '{print $2}'


As an aside; you don't need grep in this command:

$ <CMD> | awk '!/^ii/{print $2}'

Problem is that dpkg-query outputs information about no matching
packages in stderr in a not suitable for scripts way, for example

     dpkg-query -W -f='${db:Status-Abbrev}${binary:Package}\n' git gawk cmake
     un cmake
     ii git
     dpkg-query: no packages found matching gawk

I there any scriptable way to get information about unmatching packages?


You could try to redirect STDERR  to STDOUT:

$ dpkg-query -W -f='${db:Status-Abbrev}${binary:Package}\n' git gawk cmake 2>&1 | awk '{print $6}'
git
gawk
cmake

Note that my mailer is folding the command.


$ dpkg-query -W -f='${db:Status-Abbrev}${binary:Package}\n' awk git gawk cmake 2>&1 | awk '!/^ii/ || !/^un/{print $6}'
git
gawk
cmake

--
John Doe


Reply to: