Afficher un message
Vieux 13/03/2008, 19h35   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Multiple shell commands using find's -exec

2008-03-13, 18:39(+01), pk:
> Jeenu wrote:

[...]
>> I'm just wondering whether there is a way of executing multiple shell
>> commands with find's -exec switch? If either of ";", "&&" or "|" is
>> used in between commands, then shell will interpret it as two separate
>> shell commands and some times fail. I can't even use \; since find
>> interprets it as the end of it's arguments. Any other go, than putting
>> all commands into a script?

[...]
> $ find -exec sh -c "wc -l '{}'; head -n 2 '{}' && tail -n 2 '{}'" \;

[...]

That's non-standard and dangerous. Standardly, you can only
expect {} to be expanded to the filename if it consistutes an
argument of find by itself.

find ... -exec ... {} \; # OK
find ... -exec ... x{} \; # NOK

find ... -exec sh -c '... "x$1"' {} {} \; # OK

--
Stéphane
  Réponse avec citation
 
Page generated in 0,05548 seconds with 9 queries