Pair Programming Week 2¶
Deliverables¶
The deliverables for this exercise are two files: exercise_1.sh
and exercise_2.sh
.
Instructions https://harvard-iacs.github.io/2020-CS107/pages/coursework.html¶
Here is a very quick reminder of how to turn these exercises in. More specific instructions are provided on the course website.
You will complete these exercises in the PP2
directory on Deepnote. They should both be in the PP2
directory. When you are done with the exercises, you should download them to your computer and push them to your course repo. They should both be in the pair_programming/PP2/
directory in your course repo.
CAUTION: Remember that each group member must submit the same exercises. Each exercise should have annotations indicating the coder, recorder, and listener.
Part A¶
Write a bash script to "automate" your (responsible) git
workflow. Call it exercise_1.sh
. The specific tasks can be found below in the Notes section. Read the Notes first for some hints and suggestions. By doing this exercise, you will begin to solidify your git workflow. At this point, you may still not understand the "why" of what you're doing, but don't worry, we'll get to that soon.
Notes¶
- You should develop this script in your course repo. This means you will need to clone your course repo using a Deepnote terminal.
- You will compelete this exercise on your own since you are doing it from your private repo. You can still talk to people in your breakout room to discuss.
- You should work in the
pair_programming/PP2/
subdirectory of your course repo. - You may want to create a dummy file to commit (e.g.
touch dummy
will create an empty file). - Don't forget to
push
exercise_1.sh
to your course repo.
Tasks¶
The script should do the following:
- Prompt the user for a file to commit
- Hint: use
read -r -p <prompt_message> <file_name_variable>
- Hint: use
- Stage the file (remember, this is just
git add
) - Display the results of
git status
. - Ask the user if they wish to continue (
Y
orN
). If they respondN
then exit (hint, you can useexit 1
). - If they say
Y
then prompt the user for a commit message. - Commit the file to the local repo with the specified message (
git commit -m <message>
). - Display the results of
git status
. - Ask the user if they wish to continue (
Y
orN
). If they respondN
, then exit. - If they say
Y
then do agit push
.
Note: This script is fairly limited, but it is very nice illustration of a simple git
workflow. In fact, it is the basic workflow that you should all be using and building upon throughout the semester. Feel free to expand it (e.g. use while loops, etc). However, please continue to use git
best practices. For example, DO NOT use git add .
!
Concepts Covered¶
- Reading input from the user
- Conditional statements
- String comparisons
- git workflow
Part B¶
Write a bash script that checks all the files in the directory and prints out the filename if it is executable by you (the user). You should work with your group for this exercise. Designate a sharer, coder, and listen. Save this file as exercise_2.sh
.
Note: For testing purposes, you should create an executable script in your directory to make sure your script picks up on it. If you are missing this, then you won't know if your bash script is correct or not! We covered how to make a file executable in lecture.
Note: The find
command may be a better option (either in a bash
script or directly from the command line) if you want to test if a file is executable by other groups or the world. Testing this case is not required for this exercise.
Hints¶
You should make use of the command substitution feature of the bash shell. Before coding this up in your bash script, try the following command from the command line: echo "$( ls )"
. What happens? You will want to combine this with a bash for
loop.
Concepts Covered¶
- Command substitution
- For loops
- Conditionals
- File tests