gaz...@shell.xmission.com (Kenny McCormack):
> In article <
837cwpb...@helmutwaitzmann.news.arcor.de>,
> Helmut Waitzmann <
oe.th...@xoxy.net> wrote:
>>
>> find . -name 'my_script.sh' -exec sh -c -- \
>> 'name="${1##*/}" && dir="${1%"$name"} &&
>> CDPATH= cd -- "${dir:=./}" && sh ./"$name"' sh \{\} \;
>
> That's totally unsuitable for the OP.
>
It will solve the OP's problem. Your post will not.
Josef Möllers solution presented a shell script, which needs be
stored somewhere in a file of its own, that is, the command line
asked by Harry won't be self‐contained. This might or might not
be a problem.
Janis' solution (as he already stated) won't work with
pathological filenames, but he doesn't show how the adjustments
to correct this would be.
> Nobody is going to be able to use that unless/until they
> understand it, and, to be frank, *I* don't understand it (if I
> took enough time, I'm sure I could work it out, but why bother?)
You are free to refrain from working it out.
> and if *I* don't understand it, no way is either this OP or any
> general OP going to get it.
Do you conclude from what is incomprehensible for you will be
incomprehensible for everybody else?
Do you understand, why Janis' solution fails at "pathological"
filenames? Do you know how to solve that problem? Do you know
that on the system API level there are no such pathological
filenames, that is, the pathological effect is introduced alone
by a solution which neglects the existence of such pathological
filenames?
> Bottom line: You really can't post something like that w/o a
> detailed explanation of what it is and why you wrote it that
> way.
I don't know what parts of that solution need to be explained, as
that depends of the knowledge of the reader. Feel free to ask.
In the bottom line, my solution works like Josef's, but avoids
having a separate shell script: Instead of using a separate
script file it makes use of the
sh -c -- command_line sh parameters...
invocation mechanism of the shell. To understand what that is,
consult the explanation of the "-c" invocation option of the
shell in the shell's manual page. It boils down to invoke the
shell with the option "-c" and a shell script's content supplied
as the first non‐option operand: "command_line".
Compare the contents of the command_line parameter with the
contents of Josef's shell script: The command_line parameter
resembles the following shell script:
name="${1##*/}" &&
dir="${1%"$name"}" &&
CDPATH= cd -- "${dir:=./}" &&
sh ./"$name"
Compare with Josef's shell script: Do you see the relationship?
dir="${1%/*}"
script="${1##*/}"
cd "$dir" && sh "$script"
Now, for the differences between the two: Answer the following
questions:
What will the contents of the "dir" variable be, when Harry
happens to invoke his "find" command with the root directory ("/")
as the starting point? To what directory will the "cd" command
change when the "find" command finds the "/my_script.sh" file?
What will the "cd" command do, if Harry happens to invoke his
"find" command with a directory the name of starts with a "-"?
What will the "cd" command do, if the CDPATH environment variable
happens to be defined?
For the answers, look into the description of the ${var%pattern}
variable expansion and into the description of the "cd" shell
builtin command in the shell manual page.
You are free of course to present a solution which is easier to
understand.