~johanvandegriff/unix-shell-programming-revised-edition-programs

ref: 2b467c818c691e6c743c2e147522f97443d4ba3c unix-shell-programming-revised-edition-programs/change -rw-r--r-- 819 bytes
2b467c81Johan Vandegriff added license 1 year, 8 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh

#
# change an entry in the phonebook
#

name=$1

#
#  get matching entries and save in temp file
#

grep "$name" $PHONEBOOK > /tmp/matches$$

if [ ! -s /tmp/matches$$ ]
then
  echo "I cannot  find $name in the phone book."
  exit 1
fi

#
# Display matching entries one at a time and confirm change.
#

exec < /tmp/matches$$

while read line
do
  . ~/programs/phonebook/display "$line"
  echo -n "Change this entry (y/n)? "
  read answer < /dev/tty

  if [ "$answer" = y ]
  then
    break
  fi
done
if [ "$answer" != y ]
then
  exit
fi
exec < /dev/tty
display $line > /tmp/ed$$
trap "" 2
cd /tmp
nano ed$$
grep -v "^$line$" $PHONEBOOK > /tmp/phonebook$$
tr '\n' '^' < /tmp/ed$$  >>/tmp/phonebook$$
echo  >>/tmp/phonebook$$
>>/tmp/phonebook$$
sort -o /tmp/phonebook$$ $PHONEBOOK
rm /tmp/ed$$ /tmp/phonebook$$