StinsonMaster StinsonMaster - 4 years ago 106
Bash Question

Use generated argument array/string in find

I want to pass a generated argument array (or string) to a find command in bash, but everything I tried doesn't work. It seems to be something with the quoting, but I don't know how to solve this.

Here is what I tried.

excludes+=(" -not -path \"./cache/*\"")
excludes+=(" -not -path \"./tmp/*\"")
find $path -type f \( "${excludes[@]}" \) >test.txt

I just get this message
find: Der Pfad muß vor dem Suchkriterium stehen: -not -path "./cache/*"

Answer Source

You don't need to quote multiple arguments, try:

excludes=( -not -path "./cache/*" -not -path "./tmp/*" )
find "$path" -type f \( "${excludes[@]}" \) >test.txt
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download