Example: Once the add-apt-repository
process has terminated, immediately run apt-get update
– without having to enter the command manually.
Is there a way to do this? Is it possible to set such a combination without the use of the sudo
password? (although I don't mind either way)
I'm asking the following: How can I link two commands together, so that whenever I execute a particular command, it always executes the the linked command after it?
Best Answer
There are various issues hooking into this with an alias or a simple bash function, but you can write a little wrapper for a command and stick it in
/usr/local/bin
which takes priority in your path.This is a little trick to create a script and chmod it at the same time.
It'll dump an executable wrapper script in
/usr/local/bin/add-apt-repository
.To reverse this, just delete
/usr/local/bin/add-apt-repository
.If you want to do something fruitier (like linking
apt-get install
andapt-get update
so you always update before installing), we just need to expand the script to look at the arguments.Though consider that this will run an update before every
apt-get install
call. This might sound helpful but could be really tedious in practice.