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
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.
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
#!/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
$ chmod 744 testscript.sh $ ./testscript.sh
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.