Returning values from child to parent shell

I need to send the status from child shell failure to parent shell. I would like to know how could we accomplish this.

My parent.sh is as below:

#!/bin/ksh
set -x
echo "I am in parent shell now..."
child.sh
ret_stat=$?
echo "rest_stat=$ret_stat"
echo "I am below parent shell end..."

My child.sh is as below:
#!/bin/ksh
set -x
cho "I am in child shell now..." > test.log 2>&1
if [[ $? -ne 0 ]]
then
exit 100
fi
echo "I am in child shell end.."

I would like to capture the failure status from child.sh The statement in bold in child.sh is mistyped. I would like the 100 (failure) status sent to parent shell. Note that I would also like to re-direct my output to test.log at the same time.

Per above, I get success(0) status in my parent.sh ret_stat variable after the call to child.sh. This is happening because of redirection into the log file.
I would like the child shell to return 100 (failure) to parent ret_stat variable.

Let me know how would we accomplish this with the re-direction to log in the child.

Hope I made my self clear.

Thanks,
AC

No problem with the redirection. This would only be a problem if you had any output from the child.sh that was getting assigned to a variable in parent.sh.

Do you have the current working directory in your path? If not, then parent.sh will not be able to execute the child.sh script, as it will not find it in the path.

You have to change the child.sh line in your code to ./child.sh.

parent.sh

#!/bin/ksh
#set -x
echo "I am in parent shell now..."
./child.sh
ret_stat=$?
echo "rest_stat=$ret_stat"
echo "I am below parent shell end..."

child.sh

#!/bin/ksh
#set -x
cho "I am in child shell now..." > test.log 2>&1
if [[ $? -ne 0 ]]
then
exit 100
fi
echo "I am in child shell end.."

Cheers!

There is a small correction in my parent.sh as below

#!/bin/ksh
set -x
echo "I am in parent shell now..."
child.sh >> logfile
ret_stat=$?
echo "rest_stat=$ret_stat"
echo "I am below parent shell end..."

Notice that I am re-directing the output of child.sh to logfile. And now when I check the status of ret_stat, it is successful even though thhe child fails...
this is because of re-direction.

I would like to capture the failure status here.....

Sorry for the confusion earlier.

Thanks in advance.

Strange, I redirected the output of child.sh just like you have. The script still works fine. Return value is still 100. Have you tried to do as I had said in my previous post? The "./child.sh" change?

That's pretty wierd, i tested the redirection with my shell, I got sucess 0. Can we redirect the ./child.sh to logfile?