Register
It is currently Mon Jul 28, 2014 4:18 am

baps - (B)(A)sh (P)honebook (S)cript


All times are UTC - 6 hours


Post new topic Reply to topic  [ 12 posts ] 
Author Message
 PostPosted: Tue Oct 25, 2005 12:05 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
QUITE a few changes :D :D :D

Code:
#!/bin/bash
#
##########################
# USA Linux Users Group  #
# http://www.usalug.org  #
# http://bashscripts.org #
##########################

#######################################################
#     baps - (B)(A)sh (P)honebook (S)cript                #
#######################################################
#
#
#    FILE: baps
# VERSION: See variable below
#    DATE: See variable below
#
#  AUTHOR: Crouse - Please visit bashscripts.org and usalug.org
#
#
########################################################

######################
# Start of Variables #
######################
#
#
#########################################################
                                                       ##
baps_version="0.1.1"                                   ##
revision_date="Modified October 25, 2005"              ##
author="Created by: Dave Crouse"                       ##
                                                       ##
#########################################################
#
#
######################
# End of Variables   #
######################

mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data
cat /dev/null > ~/.baps/temp.data


headerfile ()
{
clear; echo "
(B)(A)sh (P)honebook (S)cript
                baps - Version $baps_version ";
echo "*****************************************************";
echo "   The results returned for a search of: $searchforthis" ;
echo "     ______________________________________";
sort -d ~/.baps/temp.data | nl -ba ;
echo "     ______________________________________";
echo "";
echo "*****************************************************";
}

mainmenu ()
{
menu="     s)earch a)dd  r)emove  e)xit"
while true; do

headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option

case $option in
      s)   searchrecords; ;;
      a)   addrecord; ;;
      r)   removerecord; ;;   
      e) exit; ;;


       # help)   helpfile ; ;;
       list)  listallrecords; ;;
      alias)  echo "alias baps='sh $PWD/baps.sh'" >> ~/.bashrc; ;;
      clear) rm ~/.baps/temp.data; ;;           
      erase) erasephonebook ;;     
      *)   echo "Sorry, that isn't an option, try again. "; sleep 2;  ;;
   esac
done;
}

addrecord ()
{
clear; echo "
(B)(A)sh (P)hone (S)cript
                baps - Version $baps_version ";
read -p "ADDING RECORD: Enter Name " name;
read -p "ADDING RECORD: Enter Phone Number " number;
entry="$name $number"
echo $entry >> ~/.baps/phone.data
echo "Record Added: $entry"; sleep 1;

}

searchrecords ()
{
cat /dev/null > ~/.baps/temp.data
  read -p "Search for : " searchforthis
     if [[ $searchforthis != "" ]]
      then
   grep -i "$searchforthis" ~/.baps/phone.data > ~/.baps/temp.data
   headerfile
      else
        echo ""
   echo "Sorry, you must enter something to search for!"
   read -p "Hit any key to continue. " temp
     fi
}

erasephonebook ()
{
read -p "$USER are you sure you want to erase the entire phone directory ? y/n: " reallycontinue
if [ "$reallycontinue" = "y" ]
   then
   rm ~/.baps/phone.data; echo "!! Erasing Entire Directory !!" ; sleep 1;
   rm ~/.baps/temp.data;
fi
}

removerecord ()
{
touch ~/.baps/temp2.data; cat /dev/null > ~/.baps/temp2.data;
sort -d ~/.baps/phone.data > ~/.baps/temp2.data
mv ~/.baps/temp2.data  ~/.baps/phone.data
clear; echo "
(B)(A)sh (P)honebook (S)cript
                baps - Version $baps_version ";
echo "************ Removing Record **************************";
echo "     ______________________________________";
echo " Line Number   | Record";
nl -ba ~/.baps/phone.data
echo "     ______________________________________";
echo " ";
echo "************ Removing Record **************************";
     read -p "Enter the line number of the record you would like to delete : " removeline;
     if [[ $removeline != "" ]]
     then
         cat /dev/null > ~/.baps/temp2.data;
         cat ~/.baps/phone.data | sed ''$removeline'd' > ~/.baps/temp2.data;
         mv ~/.baps/temp2.data ~/.baps/phone.data
    echo "Record Removed!" ; sleep 1;
     fi
}

listallrecords ()
{
clear; echo "
(B)(A)sh (P)honebook (S)cript
                baps - Version $baps_version ";
echo "*********** Listing all entries **********************";
sort -d ~/.baps/phone.data | nl -ba ;
echo "*********** Listing all entries **********************";
read -p "Hit ENTER to continue : " anykey
}

###########################
# Program run starts here #
###########################
mainmenu
exit


Top
 Profile WWW  
 PostPosted: Thu Dec 08, 2005 12:54 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
http://steve-parker.org/sh/eg/addressbook/

Haven't looked at the code of his yet though......


Top
 Profile WWW  
 PostPosted: Tue Mar 07, 2006 12:49 pm   

Joined: Fri Oct 14, 2005 9:30 am
Posts: 61
Couldn;t you stick this code
Code:
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data
cat /dev/null > ~/.baps/temp.data

in an if bit so as then you wouldn't keep running those commands?
Code:
if [[ -d ~./baps ]]
then
echo "baps dir exists"
else
echo "it doesn't exist, will now create the dir and neccesary files. " ;
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data ;
cat /dev/null > ~/.baps/temp.data
fi


Top
 Profile WWW  
 PostPosted: Mon Jun 19, 2006 12:52 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
crudball wrote:
Couldn;t you stick this code
Code:
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data
cat /dev/null > ~/.baps/temp.data

in an if bit so as then you wouldn't keep running those commands?
Code:
if [[ -d ~./baps ]]
then
echo "baps dir exists"
else
echo "it doesn't exist, will now create the dir and neccesary files. " ;
mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data ;
cat /dev/null > ~/.baps/temp.data
fi



if you do a man mkdir you will see that the -p option does that already.....

-p, --parents
no error if existing, make parent directories as needed


so in essence your code is checking it TWICE ..... no need.... my code checks for existing directories, if not.....creates them....


Top
 Profile WWW  
 PostPosted: Fri Jul 21, 2006 9:18 am   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
Looks good man....maybe i'll have to put your number in here :P you'll never be safe now that i have it...hehehehe


Top
 Profile YIM  
 PostPosted: Fri Sep 08, 2006 3:36 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
Code:
#!/bin/bash
#
##########################
# USA Linux Users Group  #
# http://www.usalug.org  #
# http://bashscripts.org #
##########################

#######################################################
#     baps - (B)(A)sh (P)honebook (S)cript            #
#######################################################
#                                                     #
#                                                     #
#    FILE: baps                                       #
# VERSION: See variable below                         #
#    DATE: See variable below                         #
# LICENSE: GPL                                        #
#  AUTHOR: Crouse - Please visit bashscripts.org      #
#                   and usalug.org                    #
#                                                     #
#                                                     #
#######################################################

######################
# Start of Variables #
######################
#
#
#########################################################
                                                       ##
baps_version="0.2"                                     ##
revision_date="Modified Sept 9th, 2006"                ##
author="Created by: Dave Crouse"                       ##
                                                       ##
#########################################################
#
#
######################
# End of Variables   #
######################

mkdir -p ~/.baps; touch ~/.baps/phone.data;
touch ~/.baps/temp.data;
cat /dev/null > ~/.baps/temp.data;


headerfile ()
{
clear;
echo "*****************************************************";
echo "*         (B)(A)sh (P)honebook (S)cript             *";
echo "*****************************************************";
echo " ";
echo "   The results returned for a search of: $searchforthis" ;
echo "     ______________________________________";
echo " ";
sort -d ~/.baps/temp.data | nl -ba ;
echo "     ______________________________________";
echo "";
}

mainmenu ()
{
menu="     s)earch a)dd  r)emove  e)xit"
while true; do

headerfile;
echo -e "$menu"
echo "";
read -p "Please choose one of the options above : " option

case $option in
      s)   searchrecords; ;;
      a)   addrecord; ;;
      r)   removerecord; ;;   
      e) exit; ;;


       # help)   helpfile ; ;;
       print) sort -d ~/.baps/phone.data | nl -ba | lpr ; ;;
       list)  listallrecords; ;;
      alias)  echo "alias phonebook='sh $PWD/baps.sh'" >> ~/.bashrc; ;;
      clear) rm ~/.baps/temp.data; ;;           
      erase) erasephonebook ;;     
      *)   echo "Sorry, that isn't an option, try again. "; sleep 2;  ;;
   esac
done;
}

addrecord ()
{
clear;
echo "*****************************************************";
echo "*         (B)(A)sh (P)honebook (S)cript             *";
echo "*****************************************************";
read -p "ADDING RECORD: Enter Name " name;
read -p "ADDING RECORD: Enter Phone Number " number;
entry="$name $number"
echo $entry >> ~/.baps/phone.data
echo "Record Added: $entry"; sleep 1;

}

searchrecords ()
{
cat /dev/null > ~/.baps/temp.data
  read -p "Search for : " searchforthis
     if [[ $searchforthis != "" ]]
      then
   grep -i "$searchforthis" ~/.baps/phone.data > ~/.baps/temp.data
   headerfile
      else
        echo ""
   echo "Sorry, you must enter something to search for!"
   read -p "Hit any key to continue. " temp
     fi
}

erasephonebook ()
{
read -p "$USER are you sure you want to erase the entire phone directory ? y/n: " reallycontinue
if [ "$reallycontinue" = "y" ]
   then
   cp ~/.baps/phone.data ~/.baps/phone.data~~
   rm ~/.baps/phone.data; echo "!! Erasing Entire Directory !!" ; sleep 1;
   rm ~/.baps/temp.data;
fi
}

removerecord ()
{
touch ~/.baps/temp2.data; cat /dev/null > ~/.baps/temp2.data;
sort -d ~/.baps/phone.data > ~/.baps/temp2.data
mv ~/.baps/temp2.data  ~/.baps/phone.data
clear;
echo "*****************************************************";
echo "*         (B)(A)sh (P)honebook (S)cript             *";
echo "*****************************************************";
echo "    ~~~~~~~~ Removing Record ~~~~~~~~";
echo " ";
echo "     ______________________________________";
echo " Line Number   | Record";
nl -ba ~/.baps/phone.data
echo "     ______________________________________";
echo " ";
echo "    ~~~~~~~~ Removing Record ~~~~~~~~";
     read -p "Enter the line number of the record you would like to delete : " removeline;
     if [[ $removeline != "" ]]
     then
         cat /dev/null > ~/.baps/temp2.data;
         cat ~/.baps/phone.data | sed ''$removeline'd' > ~/.baps/temp2.data;
         mv ~/.baps/temp2.data ~/.baps/phone.data
    echo "Record Removed!" ; sleep 1;
     fi
}

listallrecords ()
{
clear; sort -d ~/.baps/phone.data | nl -ba | less ;
}

###########################
# Program run starts here #
###########################
mainmenu
exit 0


Top
 Profile WWW  
 PostPosted: Fri Sep 08, 2006 10:10 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
you should do this one like you did bbips :idea:

baps name

searches all the names you have in it. :idea:


Top
 Profile YIM  
 PostPosted: Sat Sep 09, 2006 1:59 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
I just started using it again. Works good crouse ;) still think you should make it like bbips :idea:


Top
 Profile YIM  
 PostPosted: Sat Sep 09, 2006 3:19 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
coastie wrote:
I just started using it again. Works good crouse ;) still think you should make it like bbips :idea:


you mean menu driven ?


Top
 Profile WWW  
 PostPosted: Sat Sep 09, 2006 4:35 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
no, doing what you did with bbips, in that it's installed in /usr/bin. You could also add some stuff for addresses, and email addy's. My dad has been looking for an easy to use address book, this definately fits the bill. As soon as I can get Linux installed for him ;) I think that even he could use this without screwing it up ;)


Top
 Profile YIM  
 PostPosted: Sat Sep 09, 2006 7:48 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
nothing to "make" coastie :)

Just rename it to whatever you want..... and put it in /usr/bin or /usr/local/bin and it should work for everyone...... however, everyone will have their own directories with their own phone book....


Top
 Profile WWW  
 PostPosted: Sat Sep 09, 2006 7:55 pm   
User avatar

Joined: Tue May 17, 2005 12:55 am
Posts: 86
Location: Big Easy, Louisiana
nice, thanks ;)


Top
 Profile YIM  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP