Q: passing argument TWICE to find -exec

Q: passing argument TWICE to find -exec

Post by Michael Salm » Thu, 25 Aug 1994 17:37:05




|> As y'all know
|>
|> find $cwd -name aa\* -exec cp '{}' /tmp \;
|>
|> will find all files beginning with aa in the current directory and copy
|> them to /tmp. The find manpage says "A command argument {} is replaced
|> by the current path name." No problem so far.
|>
|> Now to give these files a unique name I try to extend them with a $$
|> (current pid) thus:
|>
|> cd /tmp
|> find $cwd -name aa\* -exec cp '{}' '{}'.$$ \;
|>
|> This time it bombs, as the 2nd occurrence of {} is not replaced by the
|> current pathname. Is there any reason for this? Is there any way to do
|> what I want?
|>
|> This is on an SGI running Irix 4.0.5.

{} are only expanded if they are the only thing in the argument {}.$$
doesn't satisfy that. You need to write a short sh script that does
what you want and exec that.

--

Michael Salmon

#include        <standard.disclaimer>
#include        <witty.saying>
#include        <fancy.pseudo.graphics>

Ericsson Telecom AB
Stockholm

 
 
 

Q: passing argument TWICE to find -exec

Post by Anthony W. Southwor » Fri, 26 Aug 1994 00:32:48


: As y'all know

: find $cwd -name aa\* -exec cp '{}' /tmp \;

: will find all files beginning with aa in the current directory and copy
: them to /tmp. The find manpage says "A command argument {} is replaced
: by the current path name." No problem so far.

: Now to give these files a unique name I try to extend them with a $$
: (current pid) thus:

: cd /tmp
: find $cwd -name aa\* -exec cp '{}' '{}'.$$ \;

: This time it bombs, as the 2nd occurrence of {} is not replaced by the
: current pathname. Is there any reason for this? Is there any way to do
: what I want?

Try this:

    cd /tmp
    find $cwd -name aa\* -print | xargs -i cp '{}' '{}'.$$

--

CARS Information Systems Corp.          WWW: http://www.carsinfo.com/~anthony
4000 Executive Park Drive
Cincinnati, OH  45241

 
 
 

1. Q: passing argument TWICE to find -exec

: As y'all know

: find $cwd -name aa\* -exec cp '{}' /tmp \;

: will find all files beginning with aa in the current directory and copy
: them to /tmp. The find manpage says "A command argument {} is replaced
: by the current path name." No problem so far.

: Now to give these files a unique name I try to extend them with a $$
: (current pid) thus:

: cd /tmp
: find $cwd -name aa\* -exec cp '{}' '{}'.$$ \;

try:

find $cwd -name aa/* -exec cp {} \; -exec cp {} .$$ \;

hope this helps

-dave

2. Solaris Boot Using NT boot loader?

3. find -exec find -exec rm

4. AWK string manipulation

5. redirect output in find's -exec arguments

6. unix programs for users.

7. script questions - passing argument as argument to another program

8. Good SCO Open Server Book

9. How to pass arguments passed in ''s

10. Trying to use file argument twice within ksh script

11. What's the difference between in Exec and Exec exec ...

12. 'find' arguments find file containing permission

13. Q : arguments for cgi exec server-side-includes ?