But when we need a bash function to return value, be sure that it just has one echo which is for return, any other display will be returned otherwise
here how it is..
$ cat poweroff.sh
#!/bin/bash
##
## Program to test return value from bash script..
##
function power(){
#
# power(3,2)=9
# power(5,3)=125
#
local fv=$1
local sv=$2
local p=1
for i in ` seq 1 $sv ` ; do
p=` expr $p \* $fv `
done
echo $p
}
v1=${1:-3}
v2=${2:-2}
p1=$(power $v1 $v2)
echo "power($v1,$v2)=$p1"
# Done.
$ ./poweroff.sh
power(3,2)=9
No comments:
Post a Comment