LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 02-14-2003, 11:01 PM   #1
frankblack
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, 11:16 PM   #2
2damncommon
Senior Member
 
Registered: Feb 2003
Location: Calif, USA
Distribution: Debian Wheezy
Posts: 2,839

Rep: Reputation: 48
I only do basic shell scripting myself.
You start any bash shell script with:
#!/bin/bash

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-15-2003, 12:59 AM   #3
crichards
Member
 
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:

Code:
#!/bin/sh

# $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 www.tldp.org

There Is More Than One Way To Do It.
 
  


Reply


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 01:07 PM
BASH Shell program Read a configuration File minil Programming 10 01-17-2005 05:37 AM
simple Shell program for pro's ..but need some help Software Linux - Software 21 02-11-2004 02:28 AM
bash shell program help embsupafly Programming 7 11-27-2002 01:05 AM
Simple C Shell script is not so simple elconde Programming 2 09-17-2001 12:53 AM


All times are GMT -5. The time now is 10:50 PM.

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