CSc 250: Lab 1

This lab was written and designed to be completed during lab-time for cs250. This lab is not graded and does not need to be turned in. However, you should work through all of the problems, as it will help you on assignments and exams. If you cannot complete the lab in the alloted time, feel free to continue at home.

Problem 1

Write a script named create-dirs.sh that creates a directory named the in the current working directory with the following directory subtree:

.
└── the
    ├── large
    │   └── elephant
    │       ├── is
    │       │   └── blue
    │       └── was
    │           ├── happy
    │           └── orange
    └── quick
        └── brown
            ├── bear
            │   └── ate
            │       └── the
            │           └── beef
            └── fox
                └── jumped
                    └── over
                        └── the
                            └── lazy
                                └── dog

You can quickly check that your script is working correctly using the tree command. If tree is not installed on your system, you can use this less pretty command instead: find . -name '*' | sed -e 's/^/|-/' -e 's/[^-][^\/]*\//| /g' -e 's/| \([A-Za-z0-9_.]\)/| + -\1/'

Click here for the solution to problem 1

Problem 2

For this problem, assume we have a file named grades.txt that looks like this:

97 Sally Talbot st@email.az.edu
87 Jared Gonzales gonzo@email.arizona.edu
90 Donna Sloan sloand09@gmail.com
87 Mary West mwest@gmail.com
89 John Cooper jc00p@apple.com
83 Sherlock Holmes 221b4lyfe@gmail.com
77 Bob Thorton thorn@gamail.com
76 David Abraham dabe@gmil.com
99 Jimmy Smith jsmi@gmail.com
62 Fred Francis fred.francis@email.arizona.edu
50 John Watson watson.with.the.blog@apple.com
71 Bat Man batman@wayne-manor.com
73 Man Bat manbat@wayne-manor.com

Each column is separated by spaces. The first column is a grade (out of 100), the second is first name, the third is last name, and the fourth is email. Feel free to add more rows with custom data.

Write commands that do the following things with this file:

Click here for the solution to problem 2

Problem 3

Write a script that fills-in a MadLib story of your choice. You can use the MadLib script from the lecture notes as inspiration. The format of the arguments to the script should look like:

./mad-lib.sh Character1 Character2 Character3 adverb1 adverb2 adjective1 adjective2 food1 location1

Your MadLib story should use all of the provided words at least once. You can choose the story, and try out various combinations of words, but please keep them PG. If you come up with a particularly hilarious one, let me know so I can use it as an example for future courses :).

Click here for the solution to problem 3

Problem 4

Unix systems have lots of fun commands, some of which are built-in, and some of which need to be installed. As far as I know, most of these tools are not installed on Macs by default, and I believe you need root privileges to install new programs onto the Macs in GS 930. If you have your own linux machine, try installing and playing around with some of the commands from the link above.

One of the commands that should be installed on a Mac by default is banner. First, run man banner to check out how to use it, and what the command line options are. Now, let’s play around with it. Let’s play around with it. Try running the following:

$ banner "HI"
$ banner -w 40 "Star Wars"
$ banner -w 50 ":-)"
$ banner -w 50 "UofA"

Problem 5

Write a script named check-files.sh. This script should take one positional argument, which is a string to search for.

This script will search through all of the regular files (not including directories) in the current directory. If the string to search for exists in the file, the script will print FILE has the string: STRING on it’s own line If the string to search for does not in the file, the script will print: FILE is missing the string: STRING on its own line.

Let’s walk through an example. Say in our current working directory, we have the following files and directories:

$ ls
check-files.sh  documents   file1.txt   file2.csv   file4.txt   pictures    todo.txt

check-files.sh is the script we are currently writing, documents and pictures are directories, and the rest are “regular” files. The contents of each file are:

$ cat file1.txt 
This is a file!
Look at the contents!
$ cat file2.csv 
James|Content|jc@gmail.com
Bill|Sneider|bs@email.arizona.edu
Kayley|Preston|preston@ms.com
$ cat todo.txt 
* Wake up
* Brew some coffee
* Go to class
* Be content with life
$ cat file4.txt 
AAAA
BBBB
CCCC
DDDD

Based on this information, this is what a few runs of the script should result in:

$ ./check-files.sh content
./check-files.sh is missing the string: content
./file1.txt has the string: content
./file2.csv has the string: content
./file4.txt is missing the string: content
./todo.txt has the string: content
$
$ ./check-files.sh Charles
./check-files.sh is missing the string: Charles
./file1.txt is missing the string: Charles
./file2.csv is missing the string: Charles
./file4.txt is missing the string: Charles
./todo.txt is missing the string: Charles
$
$ ./check-files.sh BBB
./check-files.sh is missing the string: BBB
./file1.txt is missing the string: BBB
./file2.csv is missing the string: BBB
./file4.txt has the string: BBB
./todo.txt is missing the string: BBB
$
$ ./check-files.sh file
./check-files.sh has the string: file
./file1.txt has the string: file
./file2.csv is missing the string: file
./file4.txt is missing the string: file
./todo.txt is missing the string: file
$

Notice that the search is case-insensitive, and is not performing an exact word match.

Click here for the solution to problem 5

Problem 6

Let’s watch star wars in the terminal!

telnet towel.blinkenlights.nl

(You don’t have to watch the whole thing)