If you want to run a command or script after running apt-get
on a Debian or Ubuntu Linux system, you have a few different options:
&&
operator to chain the two commands together, like this:sudo apt-get update && my_command
This will run the apt-get update
command, and if it succeeds (i.e. returns a zero exit code), it will then run the my_command
command.
;
operator to separate the two commands, like this:sudo apt-get update; my_command
This will run the apt-get update
command and then run the my_command
command, regardless of the exit code of the apt-get update
command.
bash
&&
operator in a script, like this:#!/bin/bash sudo apt-get update && my_command
Save the script, make it executable with chmod +x script.sh
and then run it with ./script.sh
.
bash
;
operator in a script, like this:#!/bin/bash sudo apt-get update; my_command
Save the script, make it executable with chmod +x script.sh
and then run it with ./script.sh
.