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

ref: 2b467c818c691e6c743c2e147522f97443d4ba3c unix-shell-programming-revised-edition-programs/rem -rw-r--r-- 550 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
#!/bin/sh

#
# remove someone from thee phonebook
#

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

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

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

  if [ "$answer = y" ]
  then
    break
  fi
done

rm /tmp/matches$$

if [ "$answer = y" ]
then
  if grep -v "^$line$" $PHONEBOOK > /tmp/phonebook$$
  then
    mv /tmp/phonebook$$ $PHONEBOOK
    echo "Entry not removed"
  fi
fi