0

This is a follow up question regarding Bash: Execute a command in each directory with file my_suites.cfg?

The global recursive iteration in the answer in the original question is a bit too strong. I would like to limit it by checking the handled folders' names.

  • I will execute this script in a root folder which contains folders with the substring Bl.
  • There is a subfolder inside each Bl folder which contains the substring test.
  • Inside the *test folder there is usually a bin folder containing my_suites.cfg. I want to execute a variant of make command here.

There are further subfolders in *Bl folders which has the substring LwU which will contain a similar structure for the my_suites.cfg. With the previous answer using global iteration, it will traverse all of of these and it takes too long.

Is it possible to check substring of the folder's name during iteration so that any folder's with substring LwU will be skipped?

EDIT: Answer from previous question that I'm referring to:

shopt -s globstar
for d in **/; do if [[ -f "$d/my_suites.cfg" ]]; then cd "$d"; make; cd -; fi; done

Example of directory structure of a Bl folder. I want to execute commands in the test/bin folder located in the Bl folder. The test/bin folder does not necessarily have the name "test" but will contain my_suites.cfg. The folder can be named extra_test for example. There is a similar structure for the subfolder innerModuleSwU. These folders will contain the substring SwU. I want to skip processing these.

├── placeholderBl
│   ├── doc
│   │   ├── my_suites.cfg
│   │   └── src
│   ├── my_suites.cfg
│   ├── someFolderIfU
│   ├── innerModuleSwU
│   │   ├── export
│   │   ├── src
│   │   └── test
│   │       ├── bin
│   │       │   └── my_suites.cfg
│   │       └── src
│   ├── test
│   │   ├── bin
│   │   │   ├── build.spec
│   │   │   ├── my_suites.cfg
│   │   ├── src
1
  • Please edit your question and make sure it stands alone. That we can understand it without needing to read another question. Also, show us the code you are using. There are three answers in the question you link to, which one are you actually implementing? And please show us an example of the directory structure (you can use tree to print it) so we can understand what you are describing more clearly.
    – terdon
    Mar 10, 2021 at 10:46

1 Answer 1

0
#!/bin/bash

for folder in $(find / -type d 2>/dev/null | grep Bl | grep test) ;do
  [ -f "$folder"/my_suites.cfg ] || continue
  cd "$folder"
  make whatever
  cd -
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .