tags:

views:

678

answers:

6

the problem is as the title. thx!

A: 

What do you want the script to do?

You can do folder recurive stuff using find ...

pjp
+1  A: 

Have a look at the find command and check the switches -type (use d to specify directory) and -exec (to specify a command to execute).

Simon Groenewolt
+5  A: 

If you want to recurse into directories, executing a command on each file found in those, I would use the find command, instead of writing anything using shell-script, I think.

That command can receive lots of parameters, like type ti filter the types of files returned, or exec to execute a command on each result.


For instance, to find directories that are under the one I'm currently in :

find . -type d -exec echo "Hello, '{}'" \;

Which will get me somehthing like :

Hello, '.'
Hello, './.libs'
Hello, './include'
Hello, './autom4te.cache'
Hello, './build'
Hello, './modules'


Same to find the files under the current directory :

find . -type f -exec echo "Hello, '{}'" \;

which will get me something like this :

Hello, './config.guess'
Hello, './config.sub'
Hello, './.libs/memcache_session.o'
Hello, './.libs/memcache_standard_hash.o'
Hello, './.libs/memcache_consistent_hash.o'
Hello, './.libs/memcache.so'
Hello, './.libs/memcache.lai'
Hello, './.libs/memcache.o'
Hello, './.libs/memcache_queue.o'
Hello, './install-sh'
Hello, './config.h.in'
Hello, './php_memcache.h'
...


Some would say "it's not shell"... But why re-invent the wheel ?
(And, in a way, it is shell ^^ )


For more informations, you can take a look at :

Pascal MARTIN
+1  A: 

Sorry I don't understand what you are asking. The best I can guess with your question is

find -type d -exec scriptname.sh \{\} \;
mlk
A: 

For most recursive file operations, you want to use find, as the other answers explain.

There is an example of a recursive bash script included in the bash-doc package. If you've got those examples installed, it will be at /usr/share/doc/bash/examples/functions/recurse (on Debian).

ire_and_curses
+1  A: 

function RecurseDirs
{
oldIFS=$IFS
IFS=$'\n'
for f in "$@"
do
your activity here
if [[ -d "${f}" ]]; then
cd "${f}"
RecurseDirs $(ls -1 ".")
cd ..
fi
done
IFS=$oldIFS
}

dreynold