mirror of https://github.com/tLDP/LDP
Merge pull request #88 from erintherad/update-doc
update archaic and sexist example
This commit is contained in:
commit
c75eee187f
|
@ -208,73 +208,72 @@ Type the year that you want to check (4 digits), followed by [ENTER]:
|
||||||
<sect2 id="sect_08_02_02"><title>Prompting for user input</title>
|
<sect2 id="sect_08_02_02"><title>Prompting for user input</title>
|
||||||
<para>The following example shows how you can use prompts to explain what the user should enter.</para>
|
<para>The following example shows how you can use prompts to explain what the user should enter.</para>
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>michel ~/test></prompt> <command>cat <filename>friends.sh</filename></command>
|
<prompt>michel ~/test></prompt> <command>cat <filename>books.sh</filename></command>
|
||||||
#!/bin/bash
|
#!/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]: "
|
echo -n "Enter the title and press [ENTER]: "
|
||||||
read name
|
read title
|
||||||
echo -n "Enter your gender and press [ENTER]: "
|
echo -n "Enter the name of the author and press [ENTER]: "
|
||||||
read -n 1 gender
|
read author
|
||||||
echo
|
echo
|
||||||
|
|
||||||
grep -i "$name" "$friends"
|
grep -i "$title" "$books"
|
||||||
|
|
||||||
if [ $? == 0 ]; then
|
if [ $? == 0 ]; then
|
||||||
echo "You are already registered, quitting."
|
echo "You have already suggested a book, quitting."
|
||||||
exit 1
|
exit 1
|
||||||
elif [ "$gender" == "m" ]; then
|
elif [ "$author" == "shakespeare" ]; then
|
||||||
echo "You are added to Michel's friends list."
|
echo "What's in a name? That which we call a rose by any other name would smell as sweet."
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo -n "How old are you? "
|
echo -n "Enter the cost and press [ENTER]: "
|
||||||
read age
|
read cost
|
||||||
if [ $age -lt 25 ]; then
|
if [ $cost -lt 25 ]; then
|
||||||
echo -n "Which colour of hair do you have? "
|
echo "$title | $author | $cost" >> "$books"
|
||||||
read colour
|
echo "Your book is added to the database. Thank you so much!"
|
||||||
echo "$name $age $colour" >> "$friends"
|
|
||||||
echo "You are added to Michel's friends list. Thank you so much!"
|
|
||||||
else
|
else
|
||||||
echo "You are added to Michel's friends list."
|
echo "Let me look for $title by $author at the library."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
<prompt>michel ~/test></prompt> <command>cp <filename>friends.sh /var/tmp</filename>; cd <filename>/var/tmp</filename></command>
|
<prompt>michel ~/test></prompt> <command>cp <filename>books.sh /var/tmp</filename>; cd <filename>/var/tmp</filename></command>
|
||||||
|
|
||||||
<prompt>michel ~/test></prompt> <command>touch <filename>friends</filename>; chmod <option>a+w</option> <filename>friends</filename></command>
|
<prompt>michel ~/test></prompt> <command>touch <filename>books</filename>; chmod <option>a+w</option> <filename>books</filename></command>
|
||||||
|
|
||||||
<prompt>michel ~/test></prompt> <command>friends.sh</command>
|
<prompt>michel ~/test></prompt> <command>books.sh</command>
|
||||||
Hello, michel. This script will register you in Michel's friends database.
|
Hello, michel. This script will add your favorite book to the database.
|
||||||
Enter your name and press [ENTER]: michel
|
Enter the title and press [ENTER]: 1984
|
||||||
Enter your gender and press [ENTER] :m
|
Enter the name of the author and press [ENTER]: Orwell
|
||||||
You are added to Michel's friends list.
|
Enter the cost and press [ENTER]: 30
|
||||||
|
Let me look for 1984 by Orwell at the library.
|
||||||
|
|
||||||
<prompt>michel ~/test></prompt> <command>cat <filename>friends</filename></command>
|
<prompt>michel ~/test></prompt> <command>cat <filename>books</filename></command>
|
||||||
|
|
||||||
</screen>
|
</screen>
|
||||||
<para>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.</para>
|
<para>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.</para>
|
||||||
<para>Other people can now start executing the script:</para>
|
<para>Other people can now start executing the script:</para>
|
||||||
<screen>
|
<screen>
|
||||||
<prompt>[anny@octarine tmp]$</prompt> <command>friends.sh</command>
|
<prompt>[anny@octarine tmp]$</prompt> <command>books.sh</command>
|
||||||
Hello, anny. This script will register you in Michel's friends database.
|
Hello, anny. This script will add your favorite book to the database.
|
||||||
Enter your name and press [ENTER]: anny
|
Enter the title and press [ENTER]: Sense and Sensibility
|
||||||
Enter your gender and press [ENTER] :f
|
Enter the name of the author and press [ENTER]: Austen
|
||||||
How old are you? 22
|
Enter the cost and press [ENTER]: 10
|
||||||
Which colour of hair do you have? black
|
Your book is added to the database. Thank you so much!
|
||||||
You are added to Michel's friends list.
|
|
||||||
</screen>
|
</screen>
|
||||||
<para>After a while, the <filename>friends</filename> list begins to look like this:</para>
|
<para>After a while, the <filename>books</filename> list begins to look like this:</para>
|
||||||
<screen>
|
<screen>
|
||||||
tille 24 black
|
Sense and Sensibility | Austen | 10
|
||||||
anny 22 black
|
Harry Potter and the Sorcerer's Stone | Rowling | 20
|
||||||
katya 22 blonde
|
The Lord of the Rings | Tolkien | 22
|
||||||
maria 21 black
|
To Kill a Mockingbird | Lee | 12
|
||||||
|
|
||||||
--output omitted--
|
--output omitted--
|
||||||
</screen>
|
</screen>
|
||||||
<para>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 <ulink url="http://www.tldp.org/LDP/intro-linux/html/sect_04_01.html#sect_04_01_06">SUID and SGID</ulink> in the Introduction to Linux guide.</para>
|
<para>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 <ulink url="http://www.tldp.org/LDP/intro-linux/html/sect_04_01.html#sect_04_01_06">SUID and SGID</ulink> in the Introduction to Linux guide.</para>
|
||||||
|
|
Loading…
Reference in New Issue