Just to add a few points to the excellent answer by @Wilf,
you can run commands in paralell if you want for any reason, for example, an autostart
script for OpenBox might look like this:
#!/bin/bash
nitrogen --restore &
tint2 &
tilda
This will set a background image using nitrogen
, start the panel tint2
and start the Quake3-style dropdown console tilda
, all at the same time. This is useful if you don't need a program to finish before you launch the next one. Not the case for apt-get update
and apt-get upgrade
though!
Notice the &
sign at the end of each line. This will cause the shell to fork that process into the background and continue execution. Note how it's different from &&
, which is basically an and
sign, command_1 && command_2
will executecommand_1
and if it exits with success, only then run command_2
, while command_1 & command_2
will start the second right after the first.
Also, you could just stack commands to have them executed serially, like so:
#!/bin/bash
apt-get update
apt-get upgrade
This will run apt-get upgrade
after apt-get update
is finished, but regardless of the result. So even if, for example, the update quits with a network error, the upgrade will still be run.
You can also do this in one line, using the ;
sign: apt-get update ; apt-get upgrade
. Again, this solution is not optimal for these particular commands, but it might come in handy in other situations.
One quick final point, you can also break lines containing &&
as such:
command_1 &&
command_2
This will be the same as command_1 && command_2
.