function variable scope
call the following script fxn-vs.sh
#!/usr/bin/sh
function locvar
{
typeset lvar
lvar='local'
echo "fxn gvar:$gvar"
gvar='changed in fxn'
}
gvar='global'
echo "script gvar: $gvar"
locvar
echo "script lvar: $lvar"
echo "script gvar: $gvar"
function return
call the following script fxn-r.sh
#!/usr/bin/sh
function mult
{
typeset -i lvar=$1
echo "lvar is $lvar"
(( x = lvar * 2 ))
print "x :$x"
return $x
}
typeset -i num=$1
echo "script num:$num"
mult $num
result=$?
print " 2 times $num is $result"