Question 1:
Make a shell script that performs the function based on the first argument. You basically already have that from what you quoted above. Just make the file containing the function definition executable, and call that script instead of the functions. As in:
Code:
--- Start of my_script.sh
#!/bin/bash
Function1() {
# This function takes one argument
# blah blah blah
}
Function1 $1
--- End of my_script.sh
chmod u+x my_script.sh
find srcDir -name *.log -exec /path/to/my_script.sh {} \;
If the function definition is located in some other file (not meant to be used as a shell script - like .bashrc for instance), you could do this:
Code:
--- Start of my_script.sh
#!/bin/bash
source file_with_function_definition
Function1 $1
--- End of my_script.sh
chmod u+x my_script.sh
find srcDir -name *.log -exec /path/to/my_script.sh {} \;
Question 2:
Can't do what you want. The backticks are replaced before the command is executed. In other words, the substitution occurs
before the find command starts. It does not happen for each file the find command locates. So
find ... -exec `dirname {}` \; will have the backticks replaced with the command output immediately, making the command
find ... -exec . \;. If you'd like to verify, run
dirname {} on the command line and it will output a dot ( . ).
Question 3:
Can't do that either (as far as I know). xargs will only put the standard input onto the command line once. You would need to do something similar to the suggestion in #1. In other words create a shell script that intelligently handles multiple filenames. Something like:
Code:
--- Start of my_script.sh
#!/bin/bash
python pyScript $1 `dirname $1`/python.log
--- End of my_script.sh
However, keep in mind the script above would likely need to be run one-at-a-time. If you want multiple entries to run simulataneously (like having more than one "$1"-like argument) you'd have to take care of that by putting more intelligence in the script.
Also, the find command will allow you to use "{}" more than once. I've never had much use for it, but you can do things like this:
Code:
find . -maxdepth 1 -type f -exec echo {} {} \;
The find command will replace each occurrence of "{}" with the name of the matching file; you're not limited to just one.