0

I have a bash file which takes 5 inputs.

Input1 = file1
Input2 = file2
Input3 = directory1
Input4 = func
Input5 = 50

input 4 and 5 are always the same, never change.

file1 and file 2 are located inside directory1

directory1 is located inside a code directory

/code/directory1/file1
/code/directory1/file2

and there are many directories with the same structure directory(1-70) inside the code folder

/code/directory1/*
/code/directory2/*
/code/directory3/*
...
/code/directory70/*

In order to run the bash file, I have to run the command from terminal 70 times :<

Is there a way to automatically run all these folders at once?

UPDATE: the directory(1-7) each one has a different name e.g bug1, test, 4-A and so on. Even the files are different e.g. bug1.c hash.c

/code/bug1/bug1.c
code/bug1/hash.c
2
  • 4
    for d in /code/directory* ; do yourscript.sh $d/file1 $d/file2 $d func 50 ; done, assuming that file1 and file2 are in all these directories. Commented Jul 23, 2019 at 9:48
  • Also check out the find command if you need something more complex than a single directory wildcard. Commented Jul 23, 2019 at 13:37

1 Answer 1

1

Try this:

for dirs in $(ls -F /code | grep '/')
do
    eval files=( "$(ls -1 ${dirs})" )
    <ShellScript>.sh "${dirs}${files[0]}" "${dirs}${files[1]}" "${dirs%/}" func 50
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.