String 如何使用变量作为find命令的路径
有人能给我一个提示,我怎样才能使下面的bash脚本正常运行: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”是一个
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/。还是我错了?德普,没关系,选择性失明。