I have write a shell function to get the maximum of a vector.
However, the returned value from the function is not always
the correct one.
Here is the script:
maxval()
{
local max j i size arrval
size=$1 ; shift
max=-999999999
i=0
while [ $i -lt $size ]
do
arrval="$1"
if [ $max -le $arrval ]
then
max=$arrval
fi
shift
let i=i+1
done
mvvv=$max
return $max
#mvvv is a global variable
}
#I am accesing mavval via:
maxval `echo ${#ind21[@]} ${ind21[@]}`
#If I try:
max2=$mvvv
# transfering via mvvv ; not sure $? does not work.....
# it works
#If I try:
max2=$?
#does not always work.
The question is: Why I am not getting the right answer when I am transfering the output of maxval function via returned $? ?