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
INSTALLED_LIST
's content isn't going to magically update itself after you didapt-get install
. You should test eitherapt-get
's exit status, or rundpkg -l $i | grep ...
for each package. – muru Nov 9 '15 at 18:04