Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass local function to find -exec

Status
Not open for further replies.

clonny2

MIS
Jan 28, 2003
470
US
I have 2 functions in my bash script where one is called main and one is do_something.

In main i have a find -exec do_something {} \;

however, the result of the find in not getting over to the do_something function.

Can anyone tell me if this is possible, or am I doing something wrong?
 
Hi

I mostly tried something similar with [tt]xargs[/tt]. But seems that there is no way for this to work neither in [tt]find[/tt] or [tt]xargs[/tt].

Finally I used an ugly solution like below :
Code:
[highlight #eee]#!/bin/bash[/highlight]

[b]function[/b] do_something()
{
  [b]echo[/b] [i]"Doing something with '$@'"[/i]
}

[b]test[/b] [i]"$1"[/i] == [i]"do_something"[/i] && {
  [b]shift[/b]
  do_something [i]"$@"[/i]
  [b]exit[/b]
}

[b]function[/b] main()
{
  find -exec [i]"$0"[/i] do_something {} \;
}

main

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top