Bash 在查找中使用生成的参数数组/字符串
我想将生成的参数数组(或字符串)传递给bash中的find命令,但我尝试的一切都不起作用。这似乎和引用有关,但我不知道如何解决这个问题 这是我试过的Bash 在查找中使用生成的参数数组/字符串,bash,shell,unix,Bash,Shell,Unix,我想将生成的参数数组(或字符串)传递给bash中的find命令,但我尝试的一切都不起作用。这似乎和引用有关,但我不知道如何解决这个问题 这是我试过的 #!/bin/bash path="/path/to/folders/" excludes=() excludes+=(" -not -path \"./cache/*\"") excludes+=(" -not -path \"./tmp/*\"") find $path -type f \( "${excludes[@]}" \) >te
#!/bin/bash
path="/path/to/folders/"
excludes=()
excludes+=(" -not -path \"./cache/*\"")
excludes+=(" -not -path \"./tmp/*\"")
find $path -type f \( "${excludes[@]}" \) >test.txt
我刚刚收到一条消息
find:Der Pfad mußvor dem Suchkriterium stehen:-not-path“/cache/*”
您不需要引用多个参数,请尝试:
path="/path/to/folders/"
excludes=( -not -path "./cache/*" -not -path "./tmp/*" )
find "$path" -type f \( "${excludes[@]}" \) >test.txt
更准确地说,他不能引用多个论点,而将它们合并成更少的论点。这样做是他尝试的根本问题。尽管如此,他仍然可以分多个步骤构建他的
排除数组。这正是我所说的多个参数
,使用+=
分多个步骤进行构建并不是问题。