This assignment will give you some practice with both "bash scripting" and dealing with translating ideas to code. Remember your basics: be sure to "chmod +x" your file before trying to run it, remember you need to run with the "full path" or equivalent (./script.sh) Also be sure to save multiple versions of your code, especially as you move from one phase to the next.
And now: Probably the shortest set of instructions for an assignment I can give:
Implement Mad Libs.
(if you're perhaps unfamiliar — https://en.wikipedia.org/wiki/Mad_Libs )
The story is up to you, and this will be a bit of a "rolling" assignment. More details on requirements below, but first;
As of class on Feb 16, we have *technically* covered everything you need to do for Version 1 and 2 below - but on Feb 23 I will review as well as cover what will be needed for Versions 3,4 and 5. Over time, I'd like to see how far everyone gets regardless; please feel free to ask questions and to give me feedback generally. I will perhaps add more information and hints as time goes on. The only time you'll need to turn in the whole thing is when you've completed all 5 phases.
I've deliberately worded these a bit vaguely, in order to let you try to think about how to accomplish each task. Soon I may provide "further hints," but for each phase, brainstorm a bit on how you might do it — and please let me know if you come up with something different or interesting; it's one of the best things that happens in this course.
The user will be prompted for a series of words identified by parts of speech (at least 4). Upon completion, the script will print back the story to the screen. The story is up to you! (echo and read are your biggies here)
These may just end up being masterpieces. So, maybe we'd like to save them; for this we'll need unique names. Before we get to the words, we will ask for a name. Upon completion we will BOTH print the story to the screen AND save the the story with the format $usernames-story.txt — i.e. my story would be saved as johns-story.txt*
*it is possible to use spaces and/or apostrophes, but these are going to make things a bit rough with escapes and all, so I'd recommend avoiding that for now
NOTE, we haven't gone over how to do anything past here, but you're free to give it a go before we do....
Because these things can get a little naughty, we're going to prevent underage users from using the program, using the same extremely accurate and defensive system used by gaming and porn websites across the world; we're just going to ask and assume they're not lying. So, before the user is prompted for nouns and verbs et. al., we're going to ask for their age; the program should only proceed if the user is 18 or older. (Feel free to keep a list of logins?)
In which we remember that people are lazy. Revisit your phase 1 code, but let's forget the whole prompting thing. Instead, give your code the ability to generate randomly different stories (i.e. with different parts-of-speech words every time it's run). Obviously, you'll have to figure out a way to get random words, of the correct type, no less....
Dominate the world with a bot-led army of A.I. storytellers. Specifically — Prompt the user for a number, and then generate and save that many stories, with attribution to random peoples names, e.g. janesstory.txt, joesstory.txt.
Unlike many academic assignments, I fully expect that you are likely to reuse code from one Version to another* — by default I am expecting five discrete files, one for each Version. That being said, in most scripting and programming there are MANY effective ways of doing something, and if you develop a way that deviates from this number, that is fine — but it must be well documented.
*Note, if you are reusing code extensively WITHIN one Version, i.e. you find yourself copying and pasting at all, you are almost certainly doing something in a less-than-ideal way. While I'm usually a fan of "if it works it works," a good coder identifies ways to reduce that sort of repetition by making the computer to the work. Laziness is a *good* characteristic of a programmer ☺
HOW TO TURN IN:
You will not upload your files to Canvas, you will instead upload (or create) them on the FSU CCI "Torch" server. I will provide details on the how in class; but you will
- Create a folder in your home directory (on Torch) called madlibs (note, do NOT put it in your public_html directory, but directly in — e.g. /home/jrm11r/madlibs )
- Inside this directory, each version should have its own script, — the final version of which should be named mdv1.sh, mdv2.sh and so on. Feel free to litter this directory with whatever additional files you need for your workspace, just be sure your final versions correspond to this. Many of you may choose to make use of additional (DATA) files, no problem there.
I'm doing it this way for a number of reasons, one to give you more practice and lessons with Bash, especially with regard to networking. Another reason is that this allows us much more room for edits and revision, I can pop into the server and test your code easily. Additionally, I can batch download everyone's work if I need to.
You *may* deviate from the format if you have a compelling/creative programmatic reason to do so.
Finally, when you are completely done, you will "turn in" a short statement to Canvas, simply for the purpose of letting me know.