User Tools

Site Tools



Chaining with ;

So far, we've typically executed one command per line. However, we learned to pipe commands together, which is a way of combining two commands into one.

We can also tell the shell to execute two commands in succession. This is called chaining and it uses the ;, semi-colon.

chaining usage:
command1; command2

:!: Exercise: Try it:

$mkdir testdir; touch testfile.txt

The shell waits for the first command to finish before the second command completes. You can command multiple commands together.

Basic scripting

We can also write very basic scripts by adding lists of commands into a script.

:!: Exercise: Copy and paste the following text into a script and name it


#make a directory
mkdir scriptdir

#make a readmefile
touch readmefile.txt

Execute the command by returning to the command prompt and executing:

$ bash

Alternatively, you can make your script executable with the chmod command (change mode). Once it is executable, you can execute it with ./

$ chmod 744
$ ./

:!: Learn more on your own: We'll cover more about permissions later in the class. You can learn more about permissions and chmod on your own here Permissions

:!: Common pitfall: Comment your code!!! This makes your code readable to other users. Remember other user is you, 2 months from now.

:!: Common pitfall: Test your scripts frequently for proper behavior. Even the best programmers test their code every few lines.


wiki/2018chaining.txt · Last modified: 2018/07/16 14:18 by david