[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Allow `find` to use exported function for -exec*?
From: |
Kamil Dudka |
Subject: |
Re: Allow `find` to use exported function for -exec*? |
Date: |
Fri, 17 Apr 2015 10:59:26 +0200 |
User-agent: |
KMail/4.14.6 (Linux/3.19.1-201.fc21.x86_64; KDE/4.14.6; x86_64; ; ) |
On Thursday 16 April 2015 23:20:06 Dale R. Worley wrote:
> Eric Blake <address@hidden> writes:
> > On 04/15/2015 08:50 PM, Peng Yu wrote:
> >> Hi, It seems that it might be convenient to allow `find` to use
> >> exported functions from shell for -exec*? Can this feature be added in
> >> the future?
> >
> > If your shell supports function exports, then the feature already
> > exists. Merely export the function before invoking find, and make sure
> > that the -exec action of find invokes the same shell that knows how to
> > use those exported functions in the environment. And be careful of the
> > bash shellshock bug.
> >
> > But there's nothing that can be added directly to find to change the
> > situation. Function exports is a property of the shell, not of find.
>
> This depends subtly on how -exec is implemented. If it's implemented
> with one of the exec*() library functions (which I expect, given that
> there's no warning about shell metacharacters in the find manual page),
> the shell isn't invoked (assuming the program is directly executable and
> not a script).
>
> If you want to execute a shell exported function, you'd have to make
> sure your shell interprets the program name. For bash (and most
> shells), the construction would be
>
> find ... -exec bash [function] [arg] [arg] ... \; ...
Actually, you need to use the -c option of bash to make it execute the
function. Otherwise it would expect a file name containing the script
to execute.
Kamil
> find invokes bash, and bash interprets "function" relative to exported
> functions.
>
> Dale