I'm using a file to pass in paths to exclude from a find. I can generate the command and run it fine from the command-line but when I try to execute it from the script I get an error.
Here's my script:
#!/usr/bin/env bash
nots=$(while read line; do
echo -n "-not -path \"*/${line}/*\" "
done < exclude_directories.txt)
echo $nots
echo "Run this command:"
echo "find ~/files -type f $nots > ~/files.txt"
find ~/files -type f $nots > ~/files.txt
When I run the script the find command return every file - even those specified in the nots
.
Here's the output with set enabled:
$ ./dump_all_local_repo_files.sh
nots=$(while read line; do
echo -n "-not -path \"*/${line}/*\" "
done < exclude_directories.txt)
++ read line
++ echo -n '-not -path "*/.git/*" '
++ read line
++ echo -n '-not -path "*/vendor/*" '
++ read line
++ echo -n '-not -path "*/external/*" '
++ read line
++ echo -n '-not -path "*/node_modules/*" '
++ read line
++ echo -n '-not -path "*/test/*" '
++ read line
+ nots='-not -path "*/.git/*" -not -path "*/vendor/*" -not -path "*/external/*" -not -path "*/node_modules/*" -not -path "*/test/*" '
echo $nots
+ echo -not -path '"*/.git/*"' -not -path '"*/vendor/*"' -not -path '"*/external/*"' -not -path '"*/node_modules/*"' -not -path '"*/test/*"'
-not -path "*/.git/*" -not -path "*/vendor/*" -not -path "*/external/*" -not -path "*/node_modules/*" -not -path "*/test/*"
echo "Run this command:"
+ echo 'Run this command:'
Run this command:
echo "find ~/files -type f $nots > ~/files.txt"
+ echo 'find ~/files -type f -not -path "*/.git/*" -not -path "*/vendor/*" -not -path "*/external/*" -not -path "*/node_modules/*" -not -path "*/test/*" > ~/files.txt'
find ~/files -type f -not -path "*/.git/*" -not -path "*/vendor/*" -not -path "*/external/*" -not -path "*/node_modules/*" -not -path "*/test/*" > ~/files.txt
find ~/files -type f $nots > ~/files.txt
+ find /Users/ken/files -type f -not -path '"*/.git/*"' -not -path '"*/vendor/*"' -not -path '"*/external/*"' -not -path '"*/node_modules/*"' -not -path '"*/test/*"'