PDF Version Available
This document is also available in PDF format: shellcond.pdf
The PDF version includes bookmarks for easy navigation and is optimized for printing.
Accessibility Notice
This document is also available in HTML format at:
https://aholdengouveia.name/IntroLinux/labs/shellcond.html
The HTML version provides enhanced accessibility features including keyboard navigation, screen reader support, responsive design, dark mode support, and high contrast options.
Objectives:
- Learn how to do if statements, case statements, if/else statements and if/elseif/else statements. Become comfortable and competent with conditional statements. Learn more about why testing and commenting is important.
Complete the following problems
References, a video, a PowerPoint and some notes are available at my website https://www.aholdengouveia.name/IntroLinux/shellloop.html
How to turn in Scripts
- Testing must be submitted along with your code. You should submit a copy of the code and a screenshot or the results of your test so that I can see a successful run of your code. Every script should be tested. A script that doesn't run is worth 0 points.
- Comments should be done on EVERY line of code, (this is very bad practice in the real world, never do this for a job) so that I can see that you understand the code that you are submitting. Every line should have an explanation of what that line does. Comments are worth 5 points per script.
- For submission you need to submit a copy of your code (actual text NO screenshots of code allowed) and your successful test run of your code for every script.
Scripts
For these two prompts, include your first iteration of your code with the single working if statement, clearly labelled, and then the code from your finished program. Submissions that don't have both iterations will be given a 0.
- Write a script to tell a knock knock joke. Make sure the user is giving the correct input in the correct spot. This will require a nested if statement that will only finish the joke if the correct response is given. Test that each option works!
- Write a script do a choose your own adventure story about our school mascot. If you don't know what an adventure story is, is look it up or ask me. You need to have 2 conditional statements that are nested together. So for example you could have a paragraph of story and then an A or B choice, each one would lead to another paragraph and another choice. You also need to include endings, Be creative. Do not have more then the 2 nested if statements. A great example of an adventure story is at http://xkcd.com/1350/
It's better to start simple and work your way up. I have a video on my Linux FAQ playlist on YouTube if you need help. Don't try and do the whole nested statements all at once, start with the basics, use my example if you want, and make small changes.
Deliverables
One file that includes all the requested information with your name, the date, and the lab title, make sure to follow the requested pattern for scripts, an example is included with the first scripting lab