Exercise 1
Bash Quest
Complete the following 10 mini-challenges using only the terminal to reveal the secret word!
If you are using the browser version of VS Code, you must first
cd /workspacesand clone it there. Then runcode .to open it in a new VS Code window.Clone the repository at https://github.com/ds-grundlagen/bash-quest
git clone https://github.com/ds-grundlagen/bash-questOpen a VS Code window in the bash-quest directory (cd into your new folder and run
code .)Make the
check.shscript executable:chmod +x check.shRun the
check.shscript with the number of the quest you want to check:./check.sh 1When you are done, you can run the
check.shscript with thealloption to check all quests and find the secret word:./check.sh all
The Quests
Create a folder called
my_stuffGo into
my_stuffand create an empty file calledempty.txtCreate a new folder in
my_stuffcalledoutputCopy all
.txtfiles fromdata/poemsto theoutputfolder using one commandCopy all data files from
data/versionswhich have an odd numbered version (ie -v1.txt, -v3.txt etc) to theoutputfolder, using one commandUse
nanoto write this exact text tomy_stuff/about.md# About This Quest Made during Lecture 1. Shell power!Write a script
my_stuff/greeter.sh:#!/bin/bash NAME="world" # next line should print "Hello, world" using the variable above- make the script executable and run it
How many lines in
data/log.txtcontain the worderror(case insensitive)? Hint: Look upgrep -iandwc -l. Write the answer (one number) to a file calledmy_stuff/output/error.txtWrite a script
my_stuff/whereami.shthat tells prints "Your current directory is: /your/current/directory"- Hint: Look up how to set the result of a command to a variable
Final boss: fill out the missing lines of this script called
build_anthology.shand run it:
#!/bin/bash
# build_anthology.sh
# Build a deterministic anthology using only commands from Lecture 1.
# 0) IMPORTANT: Update the following paths to make sure they work relative to where you are running this script!
SRC_POEMS="data/poems"
SRC_VERS="data/versions"
OUT_DIR="output"
OUT_FILE="$OUT_DIR/anthology.txt"
# 1) Write the entire contents of about.md to the anthology. Make sure that any previous text inside the anthology.txt file gets overwritten.
# 2) Add a blank line to the anthology
# 3) Add the LAST line of each poem (one per line)
# NOTE: You might need the -q option somewhere... can you see why?
# 4) Add another blank line
# 5) Add the LAST line of each version file in the data/versions directory, but only versions that are one digit long.
# write one line per version file
# try to do this with one command instead of manually
# 6) Add a blank line
# 7) Add the exact text "Thank you!" to the end