I am writing a shell script that will ask me if I'd like to check my system for updates when I log in. If I say yes, it checks and lists the packages to be upgraded. Then, it asks me if I would like to upgrade those packages. I would like the command that asks me if I'd like to upgrade the packages to only run when there is one or more package that needs to be upgraded that was listed after sudo apt update && apt list --upgradeable
. How can I do this? Here is my script so far:
read -r -p "Would you like to check your system for updates? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
sudo apt update && apt list --upgradeable
read -r -p "Would you like to update your system? [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
sudo apt upgrade && sudo apt autoremove && sudo apt autoclean
;;
[nN][oO]|[nN])
clear
;;
*)
clear && echo "Invalid input..."
;;
esac
;;
[nN][oO]|[nN])
clear
;;
*)
clear && echo "Invalid input..."
;;
esac
It basically needs to be like this: if this bit of text is in the previous command's output, then run the next command.
Any help is much appreciated. Thanks!
apt-get
,apt-cache
etc. instead ofapt
, see https://askubuntu.com/q/990823/507051. – dessert Sep 07 '19 at 06:22apt-cache show $PACKAGE_NAME
works, but I still don't know how to make the next command read this. Would I pipe it's output? – GNULinuxOnboard Sep 07 '19 at 06:36