答:
1 #!/bin/bash
2 #
3 #######################################
4 # Script name: lookup.bash
5 # Actor: Hua Jielong
6 # Date: 2012-06-20
7 # Script purpose: do for test
8 #######################################
9 #
10 if (( $# != 1 ))
11 then
12 echo "Usage:./lookup.bash $1" >&2
13 exit
14 fi
15
16 if [ ! -e $1 ]
17 then
18 touch $1
19 chmod +rw $1
20 fi
21
22 if [ ! -w $1 ]
23 then
24 chmod +rw $1
25 fi
26
27 if [ ! -s $1 ]
28 then
29 echo "-----$1 is a empty file-----" >&2
30 fi
31
32 echo "Do you need add new record to $1, yes or no?"
33 read answer
34
35 if [[ $answer = "yes" || $answer = "y" ]]
36 then
37 echo "Please input name tel addr birthday salary!"
38
39 echo -n "input name>"
40 read name
41
42 echo -n "input tel>"
43 read tel
44
46 echo -n "input addr>"
47 read addr
48
49 echo -n "input birthday>"
50 read birthday
51
52 echo -n "input salary>"
53 read salary
54
55 echo "$name:$tel:$addr:$birthday:$salary">>$1
56
57 cat $1|while read line
58 do
59 echo "$line"
60 done|sort -n>>tmp$$
61 mv $1 $1.bak
62 mv tmp$$ $1
63 chmod 777 $1
64
65 record=`grep -n -w $name:$tel $1`
66 echo "$record"
67 fi
在脚步lookup中,询问用户是否要往文件datafile添加一条记录
最新推荐文章于 2022-02-08 22:05:52 发布