I have a function which should loop through every customer in an array and execute a grep to that directory.
test(){
set -x;
export customers=( customer1 customer2 customer3 );
export repo_path="~/repodir";
export output_path='/tmp';
for i in "${customers[@]}"
do
echo "${repo_path}/PEC/repo-${i}/build.yml"
grep 'link: ' $repo_path/PEC/repo-$i/build.yml | cut -d '/' -f 2 | sed 's/.git//g'
done | sort -u > ${output_path}/repos.txt
echo "${output_path}/repos.txt";
}
For some reason I get the following error message:
grep: ~/repodir/PEC/customer1/build.yml: No such file or directory
But when I check that exact same path I can see and read the file...
The first echo command also doesn't seem to be executing.
When I replace grep 'link: ' $repo_path/PEC/repo-$i/build.yml
with grep 'link: ' ~/repodir/PEC/repo-$i/build.yml
it does work.
I have tried various ways to define the variable like ${repo_path}
, adding different types of quotes, ... So I basically don't know what I can do to make it work anymore.