Old question, I can see, but in similar situation now. Usually I do use sudo aptitude install -P PACKAGE_NAME
, what always ask before install. However now in Debian default package manager is apt|apt-get
and it does not have this functionality. Of course I can still install aptitude
and use it... However I have wrote small sh/bash wrapper function/script for apt-get
to ask before installation. It is really raw and I wrote it as a function in my terminal.
$ f () { sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf'; read -p 'Do You want to continue (y/N): ' ans; case $ans in [yY] | [yY][eE][sS]) sudo apt-get -y install "$@";; *);; esac; }
Now, let's make it more clear:
f () {
# Do filtered simulation - without lines contains 'Inst' and 'Conf'
sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf';
# Interact with user - If You want to proceed and install package(s),
# simply put 'y' or any other combination of 'yes' answer and tap ENTER.
# Otherwise the answer will be always not to proceed.
read -p 'Do You want to continue (y/N): ' ans;
case $ans in
[yY] | [yY][eE][sS])
# Because we said 'yes' I put -y to proceed with installation
# without additional question 'yes/no' from apt-get
sudo apt-get -y install "$@";
;;
*)
# For any other answer, we just do nothing. That means we do not install
# listed packages.
;;
esac
}
To use this function as a sh/bash script simply create script file e.g. my_apt-get.sh
with content (Note: listing does not contain comments, to make it a bit shorter ;-) ):
#!/bin/sh
f () {
sudo apt-get --simulate install "$@" | grep -v '^Inst\|^Conf';
read -p 'Do You want to continue (y/N): ' ans;
case $ans in
[yY] | [yY][eE][sS])
sudo apt-get -y install "$@";
;;
*)
;;
esac
}
f "$@"
Then put it for e.g. in ~/bin/
and make it executable with $ chmod u+x ~/bin/my_apt-get.sh
. If directory ~/bin
is included in your PATH
variable, you will be able to execute it simply by:
$ my_apt-get.sh PACKAGE_NAME(S)_TO INSTALL
Please note:
- The code does use
sudo
. If you use root
account, you probably need to adjust it.
- The code does not support shell autocompletion
- Have no idea how the code works with shell patterns (e.g. "!", "*", "?", ...)
apt-get
with a suitable option. However, this hypothetical option does not seem very useful to me, frankly. – Faheem Mitha Oct 27 '14 at 16:20apt-get install
rather thanapt-cache showpkg
. – Uyghur Lives Matter Oct 27 '14 at 16:44