I want to write a shell script that loops through all directories under a directory, and call a java program with the directory name as an argument at each iteration.
So my parent directory is provided as an argument to the shell script: eg:
. myShell.sh /myFolder/myDirectory
There are 100 directories under /myFolder/myDirectory. For each “directory_i”, i want to run:
java myProg directory_i
If someone can provide me with a working shell script that’ll be perfect!
You could use
find.The myShell.sh script might look a bit like this, this is a version that will recursively process any and all subdirectories under your target.
The exact set of
findoptions available depends on your variety of unix. If you don’t want recursion, you may be able to use-maxdepthas Neeraj noted, or perhaps-prune, which starts get a bit ugly:EDIT: Added prune example.