0

I have a script that would have multiple paths (folder names).

Each folder path would have a Dockerfile, but its uncertain at what level that file would exist.

Lets say my path is "v1/airflow/1.86/src/code/"

Bu the file can be at Like for eg "v1/airflow/1.86/src/Dockerfile" or it can be at "v1/airflow/1.86/Dockerfile"

so i am trying to figure out a way where i can take a step back or cd ../ check recursively if the file exist there, if not then go one directory back, and look again and if it does, stop looking further

Any help is appreciated

1 Answers1

0

A quick & dirty solution:

dirs=$(echo v1/airflow/1.86/src/code/ | tr '/' ' ')
path=""
for element in ${dirs[@]}
do
    if [[ -z "$path" ]]; then path=$element; else path="$path/$element"; fi
    printf "%s\n" "$path"
    [[ -e "${path}/Dockerfile" ]] && printf "Found it!\n"
done

This checks from the top down. Reversing the order of the array should not be too difficult.

doneal24
  • 736