About export

Hi all,

I am calling a script from main script.
The called script (second script) have to return some value, i can use exit to pass but in exit i have to pass some other value.

i used "export Var", but this command resides in a function of second script.

could you please tell me how to pass a variable(that resides in function) of called script that has to be passed to calling script,

Thanks.

Use "return" in 2nd script and check the value in main script.

# Main Script
SCRIPT_DIRECTORY/SecondScript.sh
ret=$?
if [ $ret != 0 ]
then
exit 1
fi

#SecondScript.sh
command ...
ret=$?
if [ $ret != 0 ]
then
echo "Second script has errors"
return 1
else
echo "Second script Success"
return 0
fi

if do like this it will proceed further statements of the second script or skip execution.
remember i am exporting a variable from a function in second script.

please tell me. how return and exit will work.

Extract from "man rerurn"

exit will cause the calling shell or shell script to exit
with the exit status specified by n. If n is omitted the
exit status is that of the last command executed (an EOF
will also cause the shell to exit.)

return causes a function to exit with the return value
specified by n. If n is omitted, the return status is that
of the last command executed.