This Bash script goes through every file in /app directory.
Here is the tree hirarchy
/app
_/a
-/b
-/test/unittest/python/test.py
Problem is,,, I don't want to execute lint step. How do I exclude test directory?
...
for file in $(find /app -name '*.py'); do
filename=$(basename $file)
if [[ $filename != "__init__.py" ]] ; then
echo "$file"
pylint "${file}" --rcfile="${lint_path}" || exit 1
fi
done
This is a way to solve the problem not sure if it's right. not working!
$(find /app -name '*.py' -not -path '*test*')
for anything in $(find ...)is bad practice in general. See DontReadLinesWithFor for an explanation of why (short form: it'll mangle perfectly legal filenames), and UsingFind for alternatives (see in particular those practices using either-print0or-exec, both of which can pass all possible names correctly).filename=$(basename $file)is itself going to mangle names with spaces or expandable wildcards due to the unquoted expansion.filename=$(basename "$file")is safer, though removingbasenameentirely and making itfilename=${file##*/}is equally correct and a lot faster to execute; see BashFAQ #100 describing the syntax used.