Quote:
Originally Posted by
ashima jain
Hi,
I have created a function f1 defined in script A.sh .I have called this function in background . But I want to use its return value for another function f2 in script A.sh.
You are bringing together a few unrelated issues:
(1) While a shell function can modify a global shell variable, this works of course only if they run in the same process, because shell programming - at least those shells I know - don't have the concept of variables which are shared between processes.
(2) Your code shows that you start a child process, but you never wait for it, so even if there would be a possibility for the child process to pass information back to the parent, there is no point in the program you posted, where you would fetch this information.
(3) If the value you want to return from the function, is a small number (between 0 and 127), you can return it as the exit code of the invoked function. Of course, you still need to fetch it. You would do this by explicitly waiting for the function to finish using the
wait command. This command returns the exit status of the child. Have a look at the description of your command the man page of your shell.