Mr. D
Mr. D

Reputation: 727

launch several scripts located in subdirectories

Here is my problem. I have a directory that contains multiple sub-directories. In each sub-directory, there is at least one script sh.

I want to do a script that execute sequentially all this scripts.

I am pretty new to linux.

Thanks for your help,

Upvotes: 0

Views: 44

Answers (3)

Todd Minehardt
Todd Minehardt

Reputation: 241

find . -name "*.sh" -exec {} \;

This is a shell command which, beginning in the directory it's being run in (specified by .), finds file names that end in .sh and then executes those files (the found file is substituted in the {}). The backslash prevents the semicolon from being expanded by the shell (here, bash).

Upvotes: 2

Rakholiya Jenish
Rakholiya Jenish

Reputation: 3223

Try doing it using find and for:

for file in `find . -type f -name "*.sh"`; do sh $file; done

Use can also store it in array and do it:

array=($(find . -type f -name "*.sh"))
for file in ${array[@]};do sh $file; done

Upvotes: 1

EJK
EJK

Reputation: 12527

From the top directory, run the following command:

for f in `find . -type f -name \*.sh`; do $f; done

The find command will locate all .sh files. The output of the find command (a whitespace separated list of pathnames to the scripts) becomes the input to the for command. The for command processes each input, assigning each entry to the variable f. The "$f" executes each script.

Upvotes: 1

Related Questions