Why using dirname in find command gives dots for each match?

前端 未结 7 1461
清酒与你
清酒与你 2021-02-01 15:16

I\'m using find for a task and I noticed that when I do something like this:

find `pwd` -name \"file.ext\" -exec echo $(dirname {}) \\;

it will

相关标签:
7条回答
  • 2021-02-01 15:42

    It showing you the dots, because the process substitution is evaluated before the command is actually executed. So you've to pass your command into separate shell instance.

    As for workaround, use the following syntax:

    find $PWD -name "file.ext" -exec sh -c 'echo $(dirname {})' ';'
    

    However the easiest way to print or execute something in each directory is by -execdir, e.g.:

    find . -name "file.ext" -execdir pwd ';'
    
    0 讨论(0)
提交回复
热议问题