📄 appd.txt
字号:
Appendix D
---------
Chapter 5
---------
1.
#!/bin/bash
clear
echo "Enter your name"
read response
2.
#!/bin/bash
clear
echo "Enter your name"
read response
echo "Hello $response"
3.
#!/bin/bash
clear
echo "How much money would you like to make this year?"
read salary
4.
#!/bin/bash
clear
echo "How much money would you like to earn this year?"
read salary
let salary="$salary + 100"
5.
#!/bin/bash
clear
echo "How much money would you like to earn this year?"
read salary
let salary="$salary + 100"
echo "I think you will earn $salary"
---------
Chapter 7
---------
1.
if [ "$SALARY" -lt 30000 ]
then
echo "Higher"
fi
2.
if [ "$Fname" = "Bob" ]
then
echo "Hello, Bob"
else
echo "You're not Bob"
fi
3.
if [ "$SALARY" -lt 30000 ]
then
echo "Higher"
fi
Answer:
if [ "$SALARY" -lt 30000 ]
then
echo "Higher"
elif [ "$SALARY" -gt 30000 ]
then
echo "Lower"
fi
4.
if [ "$SALARY" -lt 30000 ]
then
echo "Higher"
elif [ "$SALARY" -gt 30000 ]
then
echo "Lower"
else
echo "Right On"
fi
5.
if [ "$SALARY" -gt 29999 ] && [ "$SALARY" -lt 30001 ]
then
echo "Right On"
fi
---------
Chapter 8
---------
1.
case $city in
"New York")
echo "New York"
;;
"Chicago")
echo "Chicago"
;;
"Boston")
echo "Boston"
;;
esac
2.
case $city in
"New York")
echo "New York"
;;
"Chicago")
echo "Chicago"
;;
"Boston")
echo "Boston"
;;
*)
echo "Incorrect city entered."
esac
3.
echo "a) Search by name"
echo "b) Search by telephone number"
echo "c) Search by employee number"
echo "q) Quit"
4.
echo "a) Search by name"
echo "b) Search by telephone number"
echo "c) Search by employee number"
echo "q) Quit"
echo " "
echo "Enter your selection: "
read selection
5.
echo "a) Search by name"
echo "b) Search by telephone number"
echo "c) Search by employee number"
echo "q) Quit"
echo " "
echo "Enter your selection: "
read selection
case $selection in
"a")
echo "Search by name"
;;
"b")
echo "Search by telephone number"
;;
"c")
echo "Search by employee number"
;;
"q")
echo "Quit"
;;
*)
echo "Incorrect menu selection."
esac
----------
Chapter 10
----------
1.
let sum=0
while [ "$sum" -lt 10 ]
do
let sum="$sum + 1"
done
2.
let sum=0
while [ "$sum" -lt 11 ]
do
let sum="$sum + 1"
echo "$sum"
done
3.
let sum=0
while [ "$sum" -lt 11 ]
do
let sum="$sum + 1"
if [ "$sum" -eq 10 ]
then
echo "sum is equal to 10"
fi
done
4.
declare flag="1"
while [ "$flag" -eq "1" ]
do
clear
echo "a) Search by name"
echo "b) Search by telephone number"
echo "c) Search by employee number"
echo "q) Quit"
echo " "
echo "Enter your selection: "
read selection
case $selection in
"a")
echo "Search by name"
;;
"b")
echo "Search by telephone number"
;;
"c")
echo "Search by employee number"
;;
"q")
set flag = "0"
;;
*)
echo "Incorrect menu selection."
esac
done
5.
let flag="1"
let color=0
while [ "$flag" -eq "1" ]
do
if [ "$color" -eq 0 ]
then
clear
let color=1
echo "Green"
fi
if [ "$color" -eq 1 ]
then
clear
let color=0
echo "Red"
fi
done
----------
Chapter 11
----------
1.
for city in Paris Rome London
do
echo "$city"
done
2.
for friend in Bob Mary Joan
do
echo "Hi, $friend"
done
3.
for friend in "Bob Smith" "Mary Jones" "Joan Adams"
do
echo "Hi, $friend"
done
4.
for friend in "Bob Smith" "Mary Jones" "Joan Adams"
do
echo "Here is my friend"
echo "Hi, $friend"
done
5.
for friend in "Bob Smith" "Mary Jones" "Joan Adams"
do
echo "Here is my friend"
echo "Hi, $friend"
if [ "$friend" = "Mary Jones" ]
then
echo "She's great!"
fi
done
----------
Chapter 12
----------
1.
#!/bin/bash
declare flag="go"
while [ "$flag" = "go" ]
do
clear
echo "Enter your name or type stop to end: "
read friend
if [ "$friend" = "stop" ]
then
break
fi
done
2.
#!/bin/bash
declare flag="go"
while [ "$flag" = "go" ]
do
clear
echo "Enter your name or type stop to end: "
read friend
if [ "$friend" = "stop" ]
then
break
fi
if [ "$friend" = "Tom" ]
then
continue
fi
done
3.
#!/bin/bash
declare flag="go"
while [ "$flag" = "go" ]
do
clear
echo "Enter your name or type stop to end: "
read friend
if [ "$friend" = "stop" ]
then
break
fi
if [ "$friend" = "Tom" ]
then
continue
fi
echo "Hello, $friend ."
done
4.
#!/bin/bash
declare fname="Bob"
declare lname="Smith"
if [ "$lname" = "Smith" ]
then
if [ "$fname" = "Bob" ]
then
echo "Hello Bob Smith"
fi
fi
5.
#!/bin/bash
for name in Bob Mary Joan
do
for degree in BS MS Ph.D.
do
echo "$name has these $degree degrees"
done
done
----------
Chapter 16
----------
5.
#!/bin/bash
echo "Bob Smith 555-1212" >> mydata
echo "Mary Jones 555-5555" >> mydata
echo "Tom Adams 555-7777" >> mydata
echo "John Smith 555-4444" >> mydata
awk '$2 ~/^Jones/ {print $1, $2, $3}'mydata
----------
Chapter 18
----------
2.
#!/bin/bash
#clear the screen
clear
# prompt the user to enter a salary
echo "How much money would you like to earn this year?"
#read characters from the keyboard
read salary
# add 100 to the value of the salary variable and assign the new value to the salary variable.
let salary="$salary + 100"
#display the message and salary on the screen
echo "I think you will earn $salary"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -