Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
String 如何使用变量作为find命令的路径_String_Variables_Path_Find - Fatal编程技术网

String 如何使用变量作为find命令的路径

String 如何使用变量作为find命令的路径,string,variables,path,find,String,Variables,Path,Find,有人能给我一个提示,我怎样才能使下面的bash脚本正常运行: path="/path/" excludepath="! -path \"/path/to/exclude/*\" " find "$path" "$excludepath" -name *."txt" -type f 当我尝试运行它时,我得到: find: `! -path "/path/to/exclude/*"': No such file or directory 提前谢谢。您的问题是,“$excludepath”是一个

有人能给我一个提示,我怎样才能使下面的bash脚本正常运行:

path="/path/"
excludepath="! -path \"/path/to/exclude/*\" "

find "$path" "$excludepath" -name *."txt" -type f
当我尝试运行它时,我得到:

find: `! -path "/path/to/exclude/*"': No such file or directory

提前谢谢。

您的问题是,
“$excludepath”
是一个单参数,即使它包含空格。要放置多个参数,请使用字符串数组而不是字符串:

excludepath=(! -path "*webshow*")
find "$path" "${excludepath[@]}" -name "*.txt" -type f

不过,这是一种巴什主义(人们无意中发现了这一点,并且不使用
bash
将需要做其他事情)。

你的确切意思是什么?根路径为$path,/path/。还是我错了?德普,没关系,选择性失明。