简体   繁体   中英

How to run bash file for (different directory) as input automatically

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 eg bug1, test, 4-A and so on. Even the files are different eg bug1.c hash.c

/code/bug1/bug1.c
code/bug1/hash.c

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM