LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script programming problem (https://www.linuxquestions.org/questions/programming-9/bash-script-programming-problem-615542/)

ArthurHuang 01-22-2008 01:26 PM

Bash script programming problem
 
I have the following items in the example.sh file

./function1
./function2
./manualFunction3
./function4

functionX will automatically run, however, manualFunction3 need some people's coorporation and time is not predictable, which means I can't use sleep to wait for its completion.

So my question is, when I have finished ./manualFunction3, how does the scripts knows and continues to run function4?

Thanks!

stlouis 01-22-2008 01:42 PM

Is Function4 dependent on manualFunction3?

If so, why NOT have manualFunction3 call Function4 when it completes everything else?


Are you currently having problems with your script? Normally, functions in a script are executed one at a time, each waiting for the previous function to complete before starting...

The way you have your's set though, looks like you are essentially spawning sub-process, which if so, you really have no control over, because once started, they are their own process...


What exactly is your script trying to accomplish?

Hobbletoe 01-22-2008 01:50 PM

Code:

./malFunction3 && ./function4
This will run ./function4 after ./malFunction3 is completely successfully. Is this what you need?

David1357 01-22-2008 02:46 PM

Quote:

Originally Posted by ArthurHuang (Post 3031631)
So my question is, when I have finished ./manualFunction3, how does the scripts knows and continues to run function4?

This kind of thing is usually solved using this kind of construct:
Code:

./function1
./function2
if ! ./manualFunction3 ; then
    exit 1;
fi
./function4

Just make sure your "manualFunction3" returns a non-zero value on failure.

ArthurHuang 01-23-2008 03:22 PM

Let me have try this one
Thanks!
Quote:

Originally Posted by Hobbletoe (Post 3031664)
Code:

./malFunction3 && ./function4
This will run ./function4 after ./malFunction3 is completely successfully. Is this what you need?


ArthurHuang 01-23-2008 03:24 PM

I can't because I can't edit and recompile manualFunction3.

And they are independent two functions and can't be called.

Thanks!
Quote:

Originally Posted by stlouis (Post 3031656)
Is Function4 dependent on manualFunction3?

If so, why NOT have manualFunction3 call Function4 when it completes everything else?


Are you currently having problems with your script? Normally, functions in a script are executed one at a time, each waiting for the previous function to complete before starting...

The way you have your's set though, looks like you are essentially spawning sub-process, which if so, you really have no control over, because once started, they are their own process...


What exactly is your script trying to accomplish?



All times are GMT -5. The time now is 02:09 AM.