Sun 17 Sep 2006 10:51:44 AM UTC, original submission:
This http://bugs.debian.org/385896 reported by WANG Yunfeng.
Short version
Bug:
ametzler@argenau:/tmp/testingfind$ find -type f -execdir echo sh -c 'file -b {} | true' \;
sh -c ./file -b d | true
Expected output
sh -c file -b ./d | true
Complete original bugreport follows:
---------------------------------------
When action "-execdir" was used with find, a string "./" was prepended
to any argument containing replace pattern "{}", leading to this error:
$ find -type f ! -name "*.gz" -execdir sh -c \
> 'file -b {} | grep -q "gzip compressed data" && mv {} {}.gz' \;
sh: ./file: No such file or directory
I've gone through codes related with this prefixing behavior in the
source code of findutils, and found these relevant lines:
line 509 in find/pred.c :
const char *prefix = (state.rel_pathname[0] == '/') ? NULL : "./";
lines 278+ in lib/buildcmd.c :
if (prefix)
{
strcpy (state->argbuf + state->cmd_argv_chars, prefix);
state->cmd_argv_chars += pfxlen;
}
...
In most cases such design was not a bad idea since {} was generally
placed alone, sometimes even quite good for dealing with unusual file
names like "-l". But if we want to do some complex operations as shown
above, this will turn to be a mess.
Possible resolution could be discarding this feature since those who
need prefix "./" can specify it explicitly at the beginning of argument;
or at least a switch to turn off this behavior should be provided.
Another possible bug concerning "-execdir" shown below:
$ pwd
/tmp
$ find / -maxdepth 1 -wholename / -execdir pwd \;
/tmp
$ find / -maxdepth 1 -wholename /boot -execdir pwd \;
/
Among these two find invocations, the latter conforms to the description
in find's manpage while the former does not. This inconsistency seems to
occur only when the matching filename was "/". I'm not sure if this is
another special handling or not.
ps: action "-okdir" works basically the same way as "-execdir".
-------------------------------
|