linux help

Hey, I'm kinda new here and I'm here to ask you for a favor. So I've got a homework on linux programming and I'll need to explain this whole script to my lecturer in tomorrow. Can any of you please explain what does each segment of this script does? Thanks in advance.

#!/bin/bash

echo '1. New entry (Name, Surname, phone number, e-mail):'
echo '2. Entry search'
echo '3. List all entries'
echo '4. Delete an entry'
echo '5. Edit an entry'
echo '6. Quit'

choice=0
while [ $choice -ne 6 ]
do

read choice

case $choice in

1)
echo 'Ener Name, surname, phone number and e-mail, separated by spaces:'
read id
echo $id >> info.txt
;;

2)
echo 'Enter id data to search for:'
read search
grep -n $search info.txt
;;

3)
echo 'Full entry-list:'
cat -n info.txt
;;

4)
echo 'Specify an entry # for removal:'
cat -n info.txt
read del
sed $del'd' info.txt>temp
mv temp info.txt
cat -n info.txt
;;

5)
echo 'Specify an entry # for editing:'
cat -n info.txt
read edit
echo 'Enter new data:'
read id
sed -i "${edit} s/.*/${id}/" info.txt
;;

6)
echo 'bye'
;;

*)
echo 'Wrong selection'
;;
esac
done
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories