I had almost the exact same question here for a windows script, but now I need to do the same in linux.
I have a script that recursively finds all .h
files and checks if there is a .cpp
file in the same directory with the same name. So far this works, but now I would like to use a Exclude.txt
file that contains folders that should be excluded. My problem is that $file
is the full path, but in Exclude.txt
I want to list only the paths relative to $pwd
. How can I do this?
#!/bin/bash
for file in $(find ${PWD} -name '*.h'); do
fileWithoutPath=$(basename $file)
fileWithoutExtension=${fileWithoutPath%.*}
prefix="$(dirname $file)/"
suffix=".cpp"
cppFile=$prefix$fileWithoutExtension$suffix
if ??? path is not listed in ./Exclude.txt ??? <--- what to put here?
if [ -f "$cppFile" ]
then
echo "FILE EXISTS"
else
echo "FILE DOES NOT EXIST"
fi
fi
done
As an example:
script is in: /u/workingDir/
Exclude has a line: foo
then all files in /u/workingDir/foo/
should be ignored.