I need to use the find command to get files that are not declared in an array.
# ALLOWED extensions
ext_allowed=("*.cs" "*.csproj" "*.sln" "*.json")
combined=""
for ext in "${ext_allowed[@]}"; do
combined="$combined -not -name "$ext""
done
This doesn't work :(
find $location $combined -not -type d
This does work, but it looks the same??
find $location -not -name ".cs" -not -name ".csproj" -not -name ".json" -not -name ".sln" -not -type d
The variable location, just holds the location of the files. I also tried it already with the -o option in between, but this also does not work.
Can anyone help me out please? Thanks
combined
as an array instead of a string variable - see for example Is there a way to expand a variable into multiple arguments without globbing in bash? – steeldriver Aug 30 '22 at 16:55$combined
contains literal quotes, which aren't there in the argumentsfind
gets withfind ... -name "*.cs" ...
. So no, it's not the same. If you didn't add those quotes when appending tocombined
, it might work by accident (in a directory where those globs don't match, and with Bash'sfailglob
andnullglob
disabled, and with none of those extensions containing whitespace themselves. Maybe some other requirements too). – ilkkachu Aug 30 '22 at 17:06