[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to conditionally search?

From: Peng Yu
Subject: Re: How to conditionally search?
Date: Sat, 28 Nov 2009 10:18:11 -0600

On Sat, Nov 28, 2009 at 4:12 AM, James Youngman <address@hidden> wrote:
> On Sat, Nov 28, 2009 at 12:09 AM, Peng Yu <address@hidden> wrote:
>> On Fri, Nov 27, 2009 at 2:54 PM, Eric Blake <address@hidden> wrote:
>>> find -name '*.py' -print -o -name '*.sh' \
>>>  -exec sh -c 'test ! -f "${1%.sh}.py"' sh {} \; -print
>> I don't quite understand how the command after -exec works. Would you
>> please let me know how "-exec sh -c 'test ! -f "${1%.sh}.py"' sh {} \;
>> -print" works?
> If find is considering the file /tmp/a/foo.sh, it runs this shell command...
> test ! -f "${1%.sh}.py"'
> with $1 set to /tmp/a/foo.sh.    To see that work, type this:
> set /tmp/a/foo.sh
> test ! -f "${1%.sh}.py"'
> echo $?

I know that {} takes the matched .sh file. I still don't understand
how the second 'sh' before '{}' work. Would you please let me know?

> To understand in more detail, please read the documentation for the
> shell (it's a feature of the GNU/Linux system, it's not built into
> find).
> The -exec primary succeeds if the shell command returns 0, that is, if
> the .py file exists.    If the -exec primary succeeds, then the -print
> primary will be executed.
> Eric's answer combines find with other Unix tools.    Understanding
> Unix shell programming more generally is essential to making good use
> of find, especially in the case of more complex tasks.
> James.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]