ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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...
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
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.