Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to write a script for ubuntu 10.0.4 to check for an application on my system. I want the script to see if the particular named application is installed, and if it is, if it needs updating. I also want the script to automatically install the app if it isn't installed, or update the application if it is installed. Like if i needed to install WINE or GIMP. I'm not sure how to structure the commands but I know I will use either apt-get, or yum to find the application.

share|improve this question

You can combine these two pieces:

dpkg-query -W -f '${status} ${package} ${version}\n' |
sed -n 's/^install ok installed //p'

This will show the names of all installed packages, including their versions. If you don't need version numbers, omit the ${version} part.

Then, run apt-get update to get updated package lists, and:

/usr/lib/update-notifier/apt-check  -p

This will tell you the names of packages for which updates are available.

An idea would be (don't take this verbatim, I'm just providing an idea):


$first_command > installed_packages
$second_command > packages_with_updates

if (grep $YOUR_PACKAGE installed_packages); then
   echo "Package is installed"
   if (grep $YOUR_PACKAGE packages_with_updates); then
      sudo apt-get -q -q update #apt-get runs in quiet mode to avoid lots of output
      echo "Update available for package"
      #Whatever you need to update the package here
   echo "Package not installed, installing..."
   #whatever you need to do to install here
share|improve this answer
It's a great start, and thank you... but how would you configure it to run a check like this for a single named package that can changed each time you run the script? If i check for vlc this time, and run it again to check for wine? – J.R. May 4 '12 at 21:15
something like YOUR_PACKAGE=$1 at the beginning. Then call it with update-package wine for wine, and update-package vlc for vlc. $1, $2, ... mean the first, second and following command line parameters. – roadmr May 4 '12 at 22:06

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.