1

Maybe I am approaching this the wrong way, so I am open for suggestions. I am trying to avoid adding the output of INSTALLED_LIST to a file. I wish to use it within a variable.

Basically, I want to check if a list (INSTALLATION_PACKAGES) of packages are installed on a system. If not, record which ones failed to install, record the information, and exit. Outside of the if statement, this works fine (see commented out line), I am just having issues implementing it within an if statement.

Thx in advance for your help.

INSTALLED_LIST=`dpkg --list`

for i in $INSTALLTION_PACKAGES; do
  apt-get -y install $i
  # echo "$INSTALLED_LIST" | grep -ie "^ii  $i "
  if ! echo "$INSTALLED_LIST" | grep -ie "^ii  $i "  ; then
    echo $i >> $FAILED_INSTALL
  fi
done
2
  • 1
    You are approaching it the wrong way - INSTALLED_LIST's content isn't going to magically update itself after you did apt-get install. You should test either apt-get's exit status, or run dpkg -l $i | grep ... for each package.
    – muru
    Commented Nov 9, 2015 at 18:04
  • 1
    Thank you... I decided to check the exit status of apt-get install.
    – jdh239
    Commented Nov 9, 2015 at 18:10

1 Answer 1

2

If you want all packages in $INSTALLATION_PACKAGES to be installed, just apt-get install all of them and then check whether any of them failed:

apt-get -y $INSTALLATION_PACKAGES
list=$(dpkg -l | grep ^ii)
for i in $INSTALLATION_PACKAGES do
    echo "$list" | grep -w "$i" || echo "$i" >> $FAILED_INSTALL
done

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.