bash-toys/toys/alice-in-unixland.sh

100 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# Feb 2013 - Command line practice exercise
# Story telling time...
# Narrator function
narrate () {
# echo narration
echo $1
echo ""
# Suspense...
sleep 1
};
narrate "ALICE IN UNIXLAND"
narrate "Creating ~/alice_in_wonderland"
mkdir -vp ~/alice_in_wonderland
cd ~/alice_in_wonderland
# Get the book strip tags, etc...
narrate "Getting Alice in Wonderland text"
wget -O - "$@" https://media.patxipierce.com/r/alice-in-wonderland | sed 's/<[^>]\+>//g' >> alice_in_wonderland.txt
narrate "Alice was board, looking at her sister book with no pictures in it."
echo "bored" >> alice.txt
narrate "When she saw a white rabbit talking about the time"
echo "$(date)" >> white_rabbit.txt
echo "Im late! Im late!" >> white_rabbit.txt
narrate "Just in time to see it pop down a large rabbit-hole under the hedge."
cat white_rabbit.txt > /dev/null
narrate "In another moment down went Alice after it,"
narrate "never once considering how in the world she was to get out again."
cat alice.txt > /dev/null
narrate "She saw on her way down cupboards and book shelves;"
cupboard=("orange_marmalade" "maps" "pictures")
bookshelf=("books")
narrate "She took down a jar from one of the shelves as she passed;"
narrate "But to her great disappointment it was empty."
echo "${cupboard[0]}=''" >> alice.txt
cupboard[0]=""
narrate "she did not like to drop the jar for fear of killing somebody,"
narrate "so managed to put it into one of the cupboards as she fell past it."
mv alice.txt tmp.txt && cat tmp.txt | sed '$d' > alice.txt
cupboard[0]=$(sed '$!d' tmp.txt) && rm -f tmp.txt
narrate "Then she fell some more..."
narrate "Until she fell in to a hump of stick and dry leaves,"
narrate "and the fall was over."
mkdir -p dry_leaves && mv alice.txt dry_leaves/
narrate "She saw the white rabbit in sight"
echo "${date}" >> white_rabbit.txt
narrate "Away went Alice like the wind and was just in time to hear it say, as it turned a corner,"
echo "Oh my ears and whiskers, how late it's getting!" >> white_rabbit.txt
narrate "Turned corner but the Rabbit was no longer to be seen:"
mv white_rabbit.txt .white_rabbit.txt
narrate "She found herself in a long, low hall,"
mkdir -p low_hall
mv dry_leaves/alice.txt low_hall/alice.txt
narrate "There were doors all round the hall"
mkdir -p low_hall/door1 low_hall/door2 low_hall/door3 low_hall/door4
narrate "but they were all locked;"
chmod 000 low_hall/door*
narrate "Suddenly she came upon a little three-legged table with a tiny golden key"
three_legged_table=("golden key")
echo ${three_legged_table[0]} >> alice.txt
# maybe someday I'll finish the chapter...