LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   list recursively files with for (https://www.linuxquestions.org/questions/programming-9/list-recursively-files-with-for-542888/)

xeon123 04-03-2007 03:40 AM

list recursively files with for
 
Hi,

i want to build a bash script that do the following:

for each java file found recursively in directory structure of n-layers
execute a command.

Thanks,
Pedro

ghostdog74 04-03-2007 04:36 AM

what's the command you want to execute. normally, using find will do what you want
Code:

find /dir -type f -name "*.java" -exec "somecommand" {} \;
or this syntax
Code:

find /dir -type f -name "*.java" -print | xargs "somecommand"

xeon123 04-03-2007 04:49 AM

And, what bash script should i write to build the following:

for each java file found recursively in directory structure of n-layers
execute a command for that file.

Sorry, but i'm a newbie in bash.

Thanks.

xeon123 04-03-2007 05:01 AM

I've tried to execute this command:

Code:

find . -type f -name "*.java" -print -exec 'cleartool.exe mklabel LABEL' {} \;
and what i've got is:
Quote:

find: cleartool.exe mklabel MDCS36_Core: No such file or directory
Since i'm a newbie in bash, i don't know how to solve this problem. I suppose that, the filename isn't passed to the cleartool command, but i dpn't know how to solve it.

Can you help me?

Thanks,
Pedro

ntubski 04-03-2007 10:45 AM

The quotes make bash think 'cleartool.exe mklabel LABEL' is one big command name. The {} should be in quotes:

Code:

find . -type f -name "*.java" -print -exec cleartool.exe mklabel LABEL '{}' \;

xeon123 04-04-2007 07:06 AM

Thank you.

Sorry for my ingnorance in bash scripts.

ntubski 04-04-2007 03:38 PM

You don't need to apologise, no one is born knowing about shell scripting :)


All times are GMT -5. The time now is 01:48 PM.