From 2cb7f7e06c907569d48543bab66e7ff6c4accada Mon Sep 17 00:00:00 2001 From: Erin Mahoney Date: Wed, 7 Aug 2019 21:06:49 -0700 Subject: [PATCH 1/2] update archaic and sexist example --- .../docbook/Bash-Beginners-Guide/chap8.xml | 83 +++++++++---------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml b/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml index 85c386ba..dfef8c71 100644 --- a/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml +++ b/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml @@ -208,73 +208,72 @@ Type the year that you want to check (4 digits), followed by [ENTER]: Prompting for user input The following example shows how you can use prompts to explain what the user should enter. -michel ~/test> cat friends.sh +michel ~/test> cat books.sh #!/bin/bash -# This is a program that keeps your address book up to date. +# This is a program that creates a favorite book library. -friends="/var/tmp/michel/friends" +books="books.txt" -echo "Hello, "$USER". This script will register you in Michel's friends database." +echo "Hello, "$USER". This script will add your favorite book to the database." -echo -n "Enter your name and press [ENTER]: " -read name -echo -n "Enter your gender and press [ENTER]: " -read -n 1 gender +echo -n "Enter the title and press [ENTER]: " +read title +echo -n "Enter the name of the author and press [ENTER]: " +read author echo -grep -i "$name" "$friends" +grep -i "$title" "$books" -if [ $? == 0 ]; then - echo "You are already registered, quitting." +if [ $? == 0 ]; then + echo "You have already suggested a book, quitting." exit 1 -elif [ "$gender" == "m" ]; then - echo "You are added to Michel's friends list." +elif [ "$author" == "shakespeare" ]; then + echo "What's in a name? That which we call a rose by any other name would smell as sweet." exit 1 else - echo -n "How old are you? " - read age - if [ $age -lt 25 ]; then - echo -n "Which colour of hair do you have? " - read colour - echo "$name $age $colour" >> "$friends" - echo "You are added to Michel's friends list. Thank you so much!" + echo -n "Enter the cost and press [ENTER]: " + read cost + if [ $cost -lt 25 ]; then + echo "$title | $author | $cost" >> "$books" + echo "Your book is added to the database. Thank you so much!" else - echo "You are added to Michel's friends list." + echo "Let me look for $title by $author at the library." exit 1 fi fi -michel ~/test> cp friends.sh /var/tmp; cd /var/tmp +michel ~/test> cp books.sh /var/tmp; cd /var/tmp -michel ~/test> touch friends; chmod friends +michel ~/test> touch books; chmod books -michel ~/test> friends.sh -Hello, michel. This script will register you in Michel's friends database. -Enter your name and press [ENTER]: michel -Enter your gender and press [ENTER] :m -You are added to Michel's friends list. +michel ~/test> books.sh +Hello, michel. This script will add your favorite book to the database. +Enter the title and press [ENTER]: 1984 +Enter the name of the author and press [ENTER]: Orwell +Enter the cost and press [ENTER]: 30 +Let me look 1894 by Orwell at the library. -michel ~/test> cat friends +michel ~/test> cat books -Note that no output is omitted here. The script only stores information about the people Michel is interested in, but it will always say you are added to the list, unless you are already in it. +Note that no output is omitted here. The script only stores information about the books that Michel is interested in. It will always thank you for your suggestion, unless you already provided it. Other people can now start executing the script: -[anny@octarine tmp]$ friends.sh -Hello, anny. This script will register you in Michel's friends database. -Enter your name and press [ENTER]: anny -Enter your gender and press [ENTER] :f -How old are you? 22 -Which colour of hair do you have? black -You are added to Michel's friends list. +[anny@octarine tmp]$ books.sh +Hello, anny. This script will add your favorite book to the database. +Enter the title and press [ENTER]: Sense and Sensibility +Enter the name of the author and press [ENTER]: Austen +Enter the cost and press [ENTER]: 10 +Your book is added to the database. Thank you so much! -After a while, the friends list begins to look like this: +After a while, the books list begins to look like this: -tille 24 black -anny 22 black -katya 22 blonde -maria 21 black +Sense and Sensibility | Austen | 10 +Harry Potter and the Sorcerer's Stone | Rowling | 20 +The Lord of the Rings | Tolkien | 22 +To Kill a Mockingbird | Lee | 12 + --output omitted-- Of course, this situation is not ideal, since everybody can edit (but not delete) Michel's files. You can solve this problem using special access modes on the script file, see SUID and SGID in the Introduction to Linux guide. From ac11af7f100c7017e0b60c6efae85b1d32654583 Mon Sep 17 00:00:00 2001 From: Erin Mahoney Date: Thu, 8 Aug 2019 09:15:00 -0700 Subject: [PATCH 2/2] fix grammar and small typo --- LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml b/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml index dfef8c71..0deb561f 100644 --- a/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml +++ b/LDP/guide/docbook/Bash-Beginners-Guide/chap8.xml @@ -252,7 +252,7 @@ Hello, michel. This script will add your favorite book to the database. Enter the title and press [ENTER]: 1984 Enter the name of the author and press [ENTER]: Orwell Enter the cost and press [ENTER]: 30 -Let me look 1894 by Orwell at the library. +Let me look for 1984 by Orwell at the library. michel ~/test> cat books