LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 08-13-2004, 10:35 AM   #1
ray5_83
LQ Newbie
 
Registered: Jul 2004
Posts: 13

Rep: Reputation: 0
Using Bash, Find script files in a directory or subdirectories within...


Hi, I doing an exercise which is looked like this:

"You are required to write a script using Bash, which can find out all the script programs under a directory and its subdirectories and then change its mode to be executable. Your script needs to satisfy the following requirements:
(a) test if the number of arguments is bigger than 1. Print out a usage message if the number of argument is 1.
(b) it can be run by the super user: root only.
(c) Before it changes file's mode, it should ask the user to confirm.
(d) It needs to print out the path of all the scripts whose permission have been modified. "

For part (a), i can use variable $1 to test if there is an argument.
For part (b), i can check using $UID=0, since root is always 0
For part (c), i just print a message and if the input is y for yes, then i continue, else i just use 'exit 0' to exit fomr this script

please correct me if i was wrong

Now the problem is i had no idea how to search for all the sript programs within the directory and its subdirectories. i also got no idea for part (d).

I would really appreaciate for any good advices given.
 
Old 08-13-2004, 11:03 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
Re: Using Bash, Find script files in a directory or subdirectories within...

Quote:
Originally posted by ray5_83
Now the problem is i had no idea how to search for all the sript programs within the directory and its subdirectories.
See "man find", or better yet "info find".
Quote:
i also got no idea for part (d).
See "man echo" or "info echo".

And in general, see "man bash" (long!)
 
Old 08-13-2004, 11:21 AM   #3
Donboy
Member
 
Registered: Aug 2003
Location: Little Rock, Arkansas
Distribution: RH, Fedora, Suse, AIX
Posts: 736

Rep: Reputation: 31
Sounds like you're going to flunk this class! LOL!

Seriously, tho... it's a bad idea to come to the forums asking people to do your homework for you. It's better to try doing everything you can to figure it out yourself and then come here with your specific questions about how to get over the hump or whatever has got you stuck.

From the looks of your post, it seems like you need some very basic help getting started. I recommend Googling for some basic help. There are lots and lots of webpages already written that will give you the answers to most of your questions.

Here is a link that will get you started...

http://www.google.com/search?hl=en&l...ll+script+bash
 
Old 10-10-2008, 12:26 PM   #4
seanr
Member
 
Registered: Jan 2005
Location: Norfolk, VA
Posts: 32

Rep: Reputation: 15
Quote:
Originally Posted by Donboy View Post
Sounds like you're going to flunk this class!
ROFL, thanks for making me laugh my ass off!
 
Old 10-10-2008, 08:42 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
I suggest you bookmark these:

http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

As mentioned, read up on 'find' and 'echo'
 
  


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
Bash script to access all files in a directory shinni Programming 5 04-24-2009 04:46 PM
copy 3 files to a directory and all subdirectories? snip128 Linux - Newbie 9 08-12-2005 10:18 PM
Copying all files from subdirectories into one directory Hegemon Linux - General 3 01-17-2005 12:25 PM
How to know the property a directory include the files and subdirectories? Xiangbuilder Linux - Newbie 3 08-31-2003 06:48 AM
Script For Moving Files In Subdirectories darkmage Linux - General 3 12-17-2002 07:34 PM


All times are GMT -5. The time now is 10:51 AM.

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