# NSCI 580A4 fall 2017

### Sidebar

NSCI 580A4

Instructors
Tai Montgomery
Erin Nishimura

wiki:2016chaining

# CHAINING AND SCRIPTING

## 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 testscript.sh: #!/bin/bash #make a directory mkdir scriptdir #make a readmefile touch readmefile.txt Execute the command by returning to the command prompt and executing: $ bash testscript.sh

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

$chmod 744 testscript.sh$ ./testscript.sh