Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 在查找中使用生成的参数数组/字符串_Bash_Shell_Unix - Fatal编程技术网

Bash 在查找中使用生成的参数数组/字符串

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

我想将生成的参数数组(或字符串)传递给bash中的find命令,但我尝试的一切都不起作用。这似乎和引用有关,但我不知道如何解决这个问题

这是我试过的

#!/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

更准确地说,他不能引用多个论点,而将它们合并成更少的论点。这样做是他尝试的根本问题。尽管如此,他仍然可以分多个步骤构建他的
排除
数组。这正是我所说的
多个参数
,使用
+=
分多个步骤进行构建并不是问题。