Find and sed together fail in macOS

huangapple go评论65阅读模式
英文:

Find and sed together fail in macOS

问题

这个命令会在删除exec以后的部分中查找文件。

find src -name "*.tsx" -o -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

LayerSelector确实出现在大多数这些文件中,而-i应该会就地替换。

然而,什么都没有发生。文件没有变化,也没有消息。

这个简单的命令有什么问题吗?


然而,这个命令可以正常工作:

sed -i "" "s/LayerSelector/LayerRenderer/g" src/**/*.tsx
英文:

This command finds files if I remove from exec onwards.

find src -name "*.tsx" -o -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

The LayerSelector is indeed in most of those files, and the -i should replace in place.

However, nothing happens. No changes in files, no message.

What is wrong with this simple command ?


However, this works fine:

sed -i "" "s/LayerSelector/LayerRenderer/g" src/**/*.tsx

答案1

得分: 3

您缺少-o子句周围的括号:

find src \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

没有括号,由于操作符优先级,这个命令:

find src -name "*.tsx" -o -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

与这个命令相同(这可能不是您想要的,因为它对*.tsx文件什么都不做):

find src \( -name "*.tsx" \) -o \( -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \; \)

另请参阅:

英文:

You are missing parentheses around the -o clause:

find src \( -name "*.tsx" -o -name "*.ts" \) -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

Without the parentheses, due to operator precedence, this:

find src -name "*.tsx" -o -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \;

is the same as this (which is probably not what you want, because it does nothing to "*.tsx" files):

find src \( -name "*.tsx" \) -o \( -name "*.ts" -exec sed -i "" "s/LayerSelector/LayerRenderer/g" {} \; \)

See also:

huangapple
  • 本文由 发表于 2023年6月16日 01:05:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76483978.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定