当前位置: 技术问答>linux和unix
高分求解!!!!
来源: 互联网 发布时间:2016-02-23
本文导语: 1. Write a Bash shell script named phone.bsh that prompts the user the to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called phones which may be found in the ~u...
1. Write a Bash shell script named phone.bsh that prompts the user the to enter first or last or
any portion of person’s name, so that can be found the appropriate entry in the phone
directory file called phones which may be found in the ~unx122/examples directory.
If the user tries to enter name as the argument on the command line, he/she will get a
warning message “You need to provide name when prompted by this script!”.
If the person’s entry does NOT exist in the file phones then it will be displayed the
following message “Name NOT found in the phone directory file!” (where Name is the
user’s input).
Sample Run #1:
$ phone.bsh Saul
You need to provide name when prompted by this script!
Sample Run #2:
$ phone.bsh
Enter a name to search for:
Saul
BERMAN SAUL NH 2533 BUSINESS STUDIES DIVISION 3380A
Sample Run #3:
$ phone.bsh
Enter a name to search for:
Tyler
Tyler not found in the phone directory file!
Tue Dec 06:Rev$
any portion of person’s name, so that can be found the appropriate entry in the phone
directory file called phones which may be found in the ~unx122/examples directory.
If the user tries to enter name as the argument on the command line, he/she will get a
warning message “You need to provide name when prompted by this script!”.
If the person’s entry does NOT exist in the file phones then it will be displayed the
following message “Name NOT found in the phone directory file!” (where Name is the
user’s input).
Sample Run #1:
$ phone.bsh Saul
You need to provide name when prompted by this script!
Sample Run #2:
$ phone.bsh
Enter a name to search for:
Saul
BERMAN SAUL NH 2533 BUSINESS STUDIES DIVISION 3380A
Sample Run #3:
$ phone.bsh
Enter a name to search for:
Tyler
Tyler not found in the phone directory file!
Tue Dec 06:Rev$
|
#!/bin/bash
phonesfile=~unx122/examples/phones
if [ $# -gt 0 ]
then
echo "You need to provide name when prompted by this script!"
exit;
fi
read -p "Enter a name to search for: " searchname
grep -i $searchname $phonesfile
if [ $? -ne 0 ]
then
echo "$searchname not found in the phone directory file!"
fi
phonesfile=~unx122/examples/phones
if [ $# -gt 0 ]
then
echo "You need to provide name when prompted by this script!"
exit;
fi
read -p "Enter a name to search for: " searchname
grep -i $searchname $phonesfile
if [ $? -ne 0 ]
then
echo "$searchname not found in the phone directory file!"
fi