1

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.

#!/bin/bash
path="/path/to/folders/"
excludes=()
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/*"

1 Answer 1

3

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

path="/path/to/folders/"
excludes=( -not -path "./cache/*" -not -path "./tmp/*" )
find "$path" -type f \( "${excludes[@]}" \) >test.txt
Sign up to request clarification or add additional context in comments.

2 Comments

More precisely, he must not quote multiple arguments in a manner that combines them into fewer arguments. Doing so is the essential problem of his attempt. He can still build his excludes array in multiple steps, though.
That is exactly what I meant by multiple arguments, doing that in multiple steps using += is not a problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.