Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Search Forums:



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-14-2010
Registered User
 

Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Help with for loops

Hi, I am starting to enhance my scripting knowledge and need some assistance with simple 1 line for loops. This may help to do a mass permissions change on a big apache doc root while I have an insane customer on my phone.

What is the best resource to learn this skill and what are some that y'all have used in the past?

Thanks for any assistance.
Sponsored Links
    #2  
Old 03-14-2010
fpmurphy's Avatar
who?
 

Join Date: Dec 2003
Location: /dev/ph
Posts: 4,045
Thanks: 35
Thanked 282 Times in 263 Posts
What shell are you using?
Sponsored Links
    #3  
Old 03-14-2010
Registered User
 

Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
I should have stated this...sorry

we use the bash shell mostly.
    #4  
Old 03-14-2010
Registered User
 

Join Date: Mar 2010
Location: la jolla, ca
Posts: 100
Thanks: 4
Thanked 3 Times in 3 Posts
What exactly are you wanting the script to do? Think about:

o What are the specifications to the names of the files you wish to change? ie, every file in a directory or some specific set of file names?

o All the files below that directory too?

o Exclude any files or directories?

o Script or a simple command?

o Execute from any directory?

o Check for errors or not?

The biggest hint I have is think clearly about what you want before you script it. The shell will do exactly what it is TOLD, not what you WANT or EXPECT!!!
Sponsored Links
    #5  
Old 03-14-2010
Registered User
 

Join Date: Sep 2007
Location: SE Mass
Posts: 193
Thanks: 0
Thanked 0 Times in 0 Posts
I'm not sure you need a loop because "chmod -R" might do what you want and if not then some "find" with "-exec" probably will.

However, if it's loops you want, this may get you started: 2005/06/02 Bash looping
Sponsored Links
    #6  
Old 03-14-2010
Registered User
 

Join Date: Oct 2008
Posts: 229
Thanks: 14
Thanked 3 Times in 3 Posts

Code:
for file in * ;do chmod +w $file(or whatever you want); done

It is not necessary to do it this way, but this is a loop example for you.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Loops Shazin Shell Programming and Scripting 4 08-04-2009 09:09 AM
For Loops msb65 UNIX for Dummies Questions & Answers 3 08-06-2008 05:00 PM
While Loops vdc UNIX for Dummies Questions & Answers 4 05-10-2005 08:55 AM
Loops within loops bthomas Shell Programming and Scripting 8 04-14-2005 01:09 PM
loops? jonas27 UNIX for Dummies Questions & Answers 1 11-06-2001 02:28 AM



All times are GMT -4. The time now is 03:25 AM.