LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 05-08-2008, 09:45 PM   #1
kdyzsa
LQ Newbie
 
Registered: May 2008
Posts: 7

Rep: Reputation: 0
sh, Bourne problem


This is a new exercise for me
1.) Create a bourne shell script that can accept 2 arguments/parameters. Name your script as housekeep_files.sh.

2.) The script will delete the files specified in the input file (1st parameter) and will send a notification through email (2nd parameter) the list of files deleted.

Sample input file: /home/mis/training/tanzs/files_to_delete.txt
ex. files_to_delete.txt
man.txt
see.txt
go.txt
no.txt

Being relatively new to this type of programming, I don't know how to approach this. How can I get the man.txt and seperate it from see.txt?
Is there any way to loop this and put it in an array while it is not end of file? Also does bourne support array? so i can put these text into an array? file[i]=??
Edit/Delete Message
 
Old 05-08-2008, 10:19 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Since this sounds like a homework question I'm going to suggest you have a look at the Advanced Bash Scripting Guide and have a go at solving the problem yourself. Commands like find and ls can tell you what files are in a directory and the info in that link will help you process them.

Once you've tried it, please post any specific problems you are having - people will be happy to help, but won't do your work for you...
 
Old 05-08-2008, 10:20 PM   #3
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
Hey There,

Bourne doesn't support real array, but you can fake them using eval. In this instance, if you just to read a file and act on each line, you can do it with a simple "while read" loop, like:

Code:
while read line
do
    YOUR ACTION $line
done<files_to_delete.txt
Hope that gets you going

, Mike
 
Old 05-09-2008, 02:15 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
According to this, one dimensional arrays are supported in newer versions of bash - it doesn't give version numbers though.
 
Old 05-09-2008, 06:55 PM   #5
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
Hey There,

Hmmm... Sounds like the Bourne Again Shell rather than the original Bourne Shell. I know that as (which is to bash as sh is to ksh, for the most part) supports them.

It depends on what your instructor wants. If he/she's asking you to write a Bourne script in Linux, it's almost impossible

, Mike
 
Old 05-09-2008, 06:59 PM   #6
eggixyz
Member
 
Registered: Apr 2008
Posts: 310

Rep: Reputation: 30
BTW,

If you are using bash you can just create them like in ksh

bob[0]=whatever

or the old way

typeset -a bob
or
declare -a bob

before adding members.

and then reference all members with ${bob[@]) or ${bob:0:1} - depending on the syntax that's supports. The newer is arrayname:element:numberOfElements, so you can specify 2 or more in the last field and get a slice/range of the array.

Best wishes,

Mike
 
  


Reply



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
Bourne and Decimals? kdyzsa Programming 4 05-07-2008 01:16 AM
Bourne Shell Programming help! radmofopunk Programming 27 04-24-2006 03:13 AM
bourne vs bash alaios Linux - Software 2 03-13-2004 12:16 AM
Bourne Again SHell help MagInnovision Linux - Newbie 2 02-04-2003 03:43 PM
Bourne shell programming noodle123 Programming 3 04-16-2002 03:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:59 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
Open Source Consulting | Domain Registration