下面的命令没有进行替换,为什么?
find ./ -name "*.dng" -exec echo `basename \{\} .dng` \;
但是这个命令有效:
find ./ -name "*.dng" -exec basename \{\} .dng \;
我实际上想做的是找到硬盘中的所有 dng 并执行以下操作:
touch -c -r {basename}.RW2 {basename}.dng
最佳答案
The following command doesn't do the subtitution, why?
find ./ -name "*.dng" -exec echo `basename \{\} .dng` \;
正如赛勒斯在 his comment 中所说的那样, bash 在调用 find
之前将 `basename\{\} .dng`
扩展为 {}
;所以 find 接收到的只是 echo {}
,它看不到 `basename\{\} .dng`
部分。
What I'm actually trying to do is to find all the dng in my hard drive and do:
touch -c -r {basename}.RW2 {basename}.dng
假设每个引用文件 (*.RW2
) 与相应的 .dng
文件位于同一目录中,我会这样做:
find . -name '*.dng' -exec sh -c '
for dng do
touch -c -r "${dng%.*}.RW2" "$dng"
done' _ {} +
关于bash - 为什么带有后缀的基本名称与 find 一起使用时在子 shell 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62355444/