LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 11-04-2003, 05:21 AM   #1
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Rep: Reputation: 30
Running a script on every file in a directory


Is there some way a bash script can pick up every filename in a directory and run an operation on it, or do I have to pipe the contents of an 'ls' to an array, create a loop, and perform the operation? I don't want to create more work than I need to...

Has anyone got a script that's an example of this that I could borrow?

Dave
 
Old 11-04-2003, 06:05 AM   #2
davee
Member
 
Registered: Oct 2002
Location: Ayrshire, Scotland
Distribution: Suse(home) RHEL (Work)
Posts: 263

Original Poster
Rep: Reputation: 30
Solved it myself...


#!/bin/bash

for i in `ls`
do
<commands here>
done


Dave
 
Old 11-04-2003, 03:34 PM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
or
find . -name \* -exec myshellscriptname {} \;

where myshellscriptname expects a filename as an argument
 
  


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
script execution - file/directory permission issue serksimper Linux - Enterprise 1 08-10-2005 04:01 PM
Shell script to copy file name with part of directory Transition Linux - General 5 01-18-2005 06:40 PM
script.sh - No such file or directory - ??? ilhbutshm Programming 5 05-26-2004 11:26 AM
Run script during file copy or create in directory neranjana Linux - General 1 01-13-2004 07:57 AM
Running a script file johnlb Linux - Newbie 2 02-19-2003 03:17 AM


All times are GMT -5. The time now is 03:37 PM.

Main Menu
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