Starting Point Code

Start by creating a week11 directory in your cs44/weeklylabs subdirectory and copying over some files:

cd ~/cs44/weeklylabs
mkdir week11
cd week11
pwd
  /home/you/cs44/weeklylabs/week11
cp ~newhall/public/cs44/week11/* .
ls
Makefile  README.adoc  fib.c  run.sh  simplescript.sh

shell programming

With several SwatDB lab assignments we have given you some bash shell scripts that when run create and clean up test code state. We are going to take a look at some example script files that you copied over first. I recommend also opening Dive into System’s Appendix 2 (Chapt 17.15), which covers some basics of bash shell programming, as a reference for getting started with shell programming.

shell script examples

These are two example Bash shell programs (or scripts) from Dive into Systems Appendix 2: Chpt 17.15

simplescript.sh

This is a very simple script with a few bash commands. Let’s first open it in an editor to get an idea of how a bash shell script works, and some example syntax.

And then you can run it at the command line like this:

./simplescript.sh

To execute a shell program, it needs to be executable.

  • To list file permissions run ls -l.

  • If the shell script file doesn’t have executable permission set, you can set its permissions to include executable using the chmod command (see Dive into Systems Appendix 2 for more information about file permissions Chpt. 17.7):

chmod 700 *.sh

run.sh

An example of a bash script that could be used to run some time runs of a program. It includes more bash scripting language features such as variables, command line options, for loop, and if-else statements.

Let’s open it in an editor to see some of this syntax, and to get an idea of what this script does.

Next, we can try running this script using the example program you copied over. Type make to build the fib executable first, then let’s run the script in some different ways.

Try running in a few different ways:

./run.sh ./fib
./run.sh ./fib 3
./run.sh ./fib 3 >& out
cat out

scripts with SwatDB labs

Finally, let’s briefly take a look at some of the scripts with your Lab 7 repo to see what it is doing. Note that these are called in the Makefile in response to make and make clean commands.

These scripts create some SwatDB instances that include some relation files and index files. Let’s open some of the .sh files and see if we can figure out what they are doing.

Take a look at the getfiles.sh script and see if you can figure out what it is doing. Note that it contains the line source ./config.sh. This executes the config.sh script first. You can open that one up and see what it contains.

You can also look at the cleanup.sh script to see what it does.

Lab 8

Finally, let’s look at the Lab 8 assignment.

Resources