[mdlug] Finding something for a cat

Mark Montague markmont at umich.edu
Mon Aug 16 21:28:09 EDT 2010


  On August 16, 2010 21:16 , Jeff Hanson <jhansonxi at gmail.com>  wrote:
> find . -type d -execdir cat '{}/alternate-i386-desktop.cfg'
> /srv/tftpboot/kickstart/always_added_packages.txt>{}/standard-alternate-i386-desktop.cfg'
> \;
>
> This results in "bash: {}/standard-alternate-i386-desktop.cfg: No such
> file or directory" as if the redirect char is causing a problem with
> find and it's not expanding the variable correctly.

Redirects are interpreted by the shell, not by find, and find does not 
invoke a shell for the commands it runs via the -exec action, it just 
passes individual arguments you give it to something like the execve() 
system call.  ("man 2 execve" for more information).

You can solve the problem by telling find to invoke a shell for you for 
each command -- the shell will then set up the I/O redirection before 
running the cat command.  Try the following (not tested):

find . -type d -execdir /bin/sh -c 'cat {}/alternate-i386-desktop.cfg /srv/tftpboot/kickstart/always_added_packages.txt>  {}/standard-alternate-i386-desktop.cfg' \;


Note the new position of the single quotes -- the entire cat command, 
including the {} substituions made by find, plus the redirection, are a 
single argument that gets passed to /bin/sh to run.

I hope this helps.

--
   Mark Montague
   mark at catseye.org




More information about the mdlug mailing list