Issue
I need a bash line to check if a ubuntu package needs an upgrade or not.
For example, I want to check if the package 'firefox' needs an upgrade using dpkg or apt-get commands.
Hypthetical Example:
# Hypothetical example pseudo-code
if [[ $(firefox_needs_upgrade) ]]; then echo "Firefox needs upgrading";fi
Solution
Bash function:
apt_needs_upgrade() {
NEEDS_UPGRADE=$(/usr/lib/update-notifier/apt-check -p 2>&1 >/dev/null | grep "^$1$" | wc -l)
if [ "$NEEDS_UPGRADE" == 1 ]; then
return 0; # 0 means true in bash!!!
else
return 1; # false
fi;
}
Use it:
if apt_needs_upgrade "firefox"; then
echo "Needs upgrading"
else
echo "No need to upgrade"
fi;
Answered By - Basil Musa Answer Checked By - Mary Flores (WPSolving Volunteer)