Return vs. Echo

In a Ksh functions, when you have both echo and return respectively - what does it do. E.g.

Func B ()
{
.....
{
.....
echo $Varaible
}
Return 0
}

Func A ()
{
$Var1 = Func B()
....
....
}

Echo $Var1 produces the value of $Variable, so where did Return 0 go? What if echo was not there then would would be the result?

Thanks
-Novice

There is no similarity between them: echo prints its arguments to stdout; return sets a return code which may be tested directly (by if or a control operator, && or ||) or indirectly in the contents of $?.

Hi cfajohnson

Thanks for the reply. In the code below GetData() calls get_primary and is_primary functions

GetData()
{

prim_mach=`get_primary`
gprim_mach=`is_primary`

echo $prim_mach
echo $gprim_mach
}

-------------------

is_primary()
{
TFILE=$TEMPDIR/tempFile.$$
this_server=`uname -n`
dbaccess << PRIM > /dev/null 2>&1
database sscDB;
unload to $TFILE select s_status from serverstbl where s_name = "$this_server";
PRIM
[ -f $TFILE ] &&
{
status=`cat $TFILE | awk -F"|" '{ print $1 }'`
rm $TFILE
[ "$status" = "P" ] && return 0
}
return 1
}

----------------

TFILE=$TEMPDIR/tempFile.$$
dbaccess << GPRIMM > /dev/null 2>&1
database sscDB;
unload to $TFILE select s_name from serverstbl where s_status = "P";
GPRIMM
[ -f $TFILE ] &&
{
status=`cat $TFILE | awk -F"|" '{ print $1 }'`
rm $TFILE
echo $status
}
return 0
}

----------------------------------------------------
echo $prim_mach prints the column value - echo is the only command I see in the code that can send the output to $prim_mach variable in GetData(). So echo sent value to $prim_mach. But it returned 0 too. How do I see the 0? I thought the variable $prim_mach will have 0 in it, but it showed the echoed value.

echo $gprim_mach prints nothing, becasue there is no echo. But it did return 0 or 1 depending upon the condition. How can I see that?

Thanks.

I repeat:

Can you please show me the syntax of how to check the exit code in getdata() ?

getdata
echo $?

If you want to check the error status of commands within getdata:

GetData()
{

prim_mach=`get_primary`
echo $?
gprim_mach=`is_primary`
echo $?

echo $prim_mach
echo $?
echo $gprim_mach
echo $?
}

Normally you would use a conditional expression and do something different depending on the exit code of the command.

Fantastic. Thanks a lot cfajohnson.