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 /workspaces and clone it there. Then run code . 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-quest
    
  • Open a VS Code window in the bash-quest directory (cd into your new folder and run code .)

  • Make the check.sh script executable:

    chmod +x check.sh
    
  • Run the check.sh script with the number of the quest you want to check:

    ./check.sh 1
    
  • When you are done, you can run the check.sh script with the all option to check all quests and find the secret word:

    ./check.sh all
    

The Quests

  1. Create a folder called my_stuff

  2. Go into my_stuff and create an empty file called empty.txt

  3. Create a new folder in my_stuff called output

  4. Copy all .txt files from data/poems to the output folder using one command

  5. Copy all data files from data/versions which have an odd numbered version (ie -v1.txt, -v3.txt etc) to the output folder, using one command

  6. Use nano to write this exact text to my_stuff/about.md

    # About This Quest
    Made during Lecture 1.
    Shell power!
    
  7. 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
  8. How many lines in data/log.txt contain the word error (case insensitive)? Hint: Look up grep -i and wc -l . Write the answer (one number) to a file called my_stuff/output/error.txt

  9. Write a script my_stuff/whereami.sh that tells prints "Your current directory is: /your/current/directory"

    • Hint: Look up how to set the result of a command to a variable
  10. Final boss: fill out the missing lines of this script called build_anthology.sh and 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

Submit the answer: