Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

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.