How does command substitution work with find?
I have the following开发者_Go百科 command
find . -name "*.tiff" -exec echo `basename -s .tiff {}` \;
I expect this to print all my .tiff-files without their file extensions. What I get is
./file1.tiff
./file2.tiff
...
The command,
find . -name "*.tiff" -exec basename -s .tiff {} \;
does yield
file1
file2
...
Is this not supposed to be the input of echo?
The content of the backticks is executed before the find command - yielding just the placeholder {}
, which is used in the find command line - hence your result. You can always use set -x
to examine what the shell is up to.
Use single-quote characters (') instead of backticks (`) - putting a command in backticks causes it to be executed and replaced by its output in your command.
Also, modify the command to get rid of the echo
, like this:
find . -name "*.tiff" -exec 'basename -s .tiff {}' \;
This will execute basename
on each found file.
精彩评论