Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-14-2003, 10:01 PM   #1
LQ Newbie
Registered: Feb 2003
Posts: 1

Rep: Reputation: 0
Question Simple Bash Shell Program

Help- I am up the proverbial creek without a paddle!

I need to write a "simple" bash shell program that will add a Last name, First name, and phone number to a file (named phone_dir) from the command line...(all three values should be added at once with a space between them) I should be able to add new entries by appending to this file. (I guess it would be a nice feature if the program also checked for duplicate phone numbers)

I haven't got a clue where to start since I am Linux-challenged.

Any help would be sincerely appreciated.

Old 02-14-2003, 10:16 PM   #2
Senior Member
Registered: Feb 2003
Location: Calif, USA
Distribution: PCLINUXOS
Posts: 2,876

Rep: Reputation: 88
I only do basic shell scripting myself.
You start any bash shell script with:

You enter commands just like you would on the command line one by one.
You save the file by whatever name you want to execute it by, and do a:
chmod +x
(as root to make it seem like a system wide application.)

Instead of using ">" to redirect to a file, use ">>" to apend to a file.

Good Luck
Old 02-14-2003, 11:59 PM   #3
Registered: Feb 2003
Location: Arizona
Distribution: Gentoo!
Posts: 124

Rep: Reputation: 15
This is a pretty simple program. You could easily add features, but the only command you need is echo.

Yes, echo.

Make a shell script with the following:


# $1 = first name
# $2 = last name
# $3 = phone number

echo "$1 $2 $3"
On the command line, type...

filename firstname lastname phonenumber >> phone_dir

You shouldn't use a shell script for this. Its not needed.

If you want to check for repeated phone numbers, read the man pages on uniq and sort.

Also, there is a great guide (The Advanced Bash Scripting Guide) on

There Is More Than One Way To Do It.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems compiling a simple shell program yekrahs Programming 3 09-26-2005 12:07 PM
BASH Shell program Read a configuration File minil Programming 10 01-17-2005 04:37 AM
simple Shell program for pro's ..but need some help Software Linux - Software 21 02-11-2004 01:28 AM
bash shell program help embsupafly Programming 7 11-27-2002 12:05 AM
Simple C Shell script is not so simple elconde Programming 2 09-16-2001 11:53 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:25 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration