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.
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 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/'
For this problem, assume we have a file named
grades.txt that looks like this:
97 Sally Talbot email@example.com 87 Jared Gonzales firstname.lastname@example.org 90 Donna Sloan email@example.com 87 Mary West firstname.lastname@example.org 89 John Cooper email@example.com 83 Sherlock Holmes firstname.lastname@example.org 77 Bob Thorton email@example.com 76 David Abraham firstname.lastname@example.org 99 Jimmy Smith email@example.com 62 Fred Francis firstname.lastname@example.org 50 John Watson email@example.com 71 Bat Man firstname.lastname@example.org 73 Man Bat email@example.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:
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 :).
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
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"
Write a script named
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,
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|Contentfirstname.lastname@example.org Bill|Sneideremail@example.com Kayley|Prestonfirstname.lastname@example.org
$ 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.
Let’s watch star wars in the terminal!
(You don’t have to watch the whole thing)