小编Thu*_*eez的帖子

“查找:路径必须在表达式之前:”仅在脚本中运行时出错

如果我在命令行执行我的 find 命令,它工作正常,但如果我在脚本中尝试它,我会收到此错误。我运行命令

FILTER=" | grep -v \"test\""
files=`find . -type f -regex \".*$ext\" $FILTER`
Run Code Online (Sandbox Code Playgroud)

如果我做

echo "find . -type f -regex \".*$ext\" $FILTER" 
Run Code Online (Sandbox Code Playgroud)

它输出

find . -type f -regex ".*.cpp" | grep -v "test"
Run Code Online (Sandbox Code Playgroud)

在命令行上工作正常。我怎样才能让它在脚本中工作?我也尝试转义 *,但得到相同的错误。

我也注意到

find . -type f -regex \".*$ext\"
Run Code Online (Sandbox Code Playgroud)

在我的 shell 脚本中运行时没有输出,我不知道为什么,因为就像上面一样,如果我在命令行运行它,我会得到一个 .cpp 文件列表。

shell scripting bash find

0
推荐指数
2
解决办法
298
查看次数

标签 统计

bash ×1

find ×1

scripting ×1

shell ×1