Fernando Linsalata
Fernando Linsalata

Reputation: 3

How do I write a bash script that goes through each directory executes a command in each directory

How do I write a bash script that traverses each directory (~100) within a parent folder and executes a command like ./xxxx.exe?

My question is:

{#!bin/bash
cd directory_A
gfortran -w xxxx.f90 -o xxxx.exe;
./xxxx.exe;

cd ..

cd directory_B
./xxxx.exe;

cd ..

cd directory_C
./xxxx.exe;
cd ..
}

Upvotes: 0

Views: 58

Answers (1)

Raman Sailopal
Raman Sailopal

Reputation: 12917

You can use find with -execdir and so:

find /pathtoparentdirectory -type d -execdir ./xxxx.exe

Search for all directory in the parent directory and then execute xxxx.exe from within each found directory.

Upvotes: 1

Related Questions