Re: function inside find
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxxxxxxx>
- Date: Wed, 31 Dec 2008 12:24:27 +0000 (UTC)
2008-12-31, 03:13(-08), marc:
Is it possible to call an own function inside find ?[...]
I've tried :
find /home/foo -type f -mtime -1 -exec copy {} \;
where copy is a function defined before, but it is never called.
The function is only known to the shell where you declare it, so
not to find not even to a shell that you may tell find to run.
You'd need to do something like:
find /home/foo -type f -mtime -1 -exec sh -c '
copy() {
cp -- "$@" /dest
}
copy "$@"' sh {} +
For instance.
But of course, you don't need to define the function.
find /home/foo -type f -mtime -1 -exec sh -c '
cp -- "$@" /dest' sh {} +
is enough.
With bash and some version of ksh, you can export functions:
copy() {
cp -- "$@" /dest
}
export -f copy
find /home/foo -type f -mtime -1 -exec bash -c '
copy "$@"' bash {} +
--
Stéphane
.
- References:
- function inside find
- From: marc
- function inside find
- Prev by Date: Re: How to tell patch to ignore line endings?
- Next by Date: Re: bash | Program startup (and termination) hook?
- Previous by thread: Re: function inside find
- Next by thread: Re: function inside find
- Index(es):
Relevant Pages
|