One shell question# Unix - 噫吁兮,危乎高哉
yy
1 楼
ne short script:
ns=0
if [ $# -eq 3 ]; then
ans=$(( $n1 $op $n2 ))
echo "$n1 $op $n2 = $ans"
return $ans
else
echo "Function cal requires atleast three args"
fi
return
}
cal 5 + 10
cal 10 - 2
cal 10 / 2
echo $?
Run result:
$ ./pass1
5 + 10 = 15
10 - 2 = 8
10 / 2 = 5
5
My question is:
why it is: ans=$(( $n1 $op $n2 ))
not: ans=( $n1 $op $n2 ) ***
I tried the *** one: the running result is:
5 + 10 = 5
10 - 2 = 10
10 / 2 = 10
10
can any exlain a little bit?
Thank you very much
s
ns=0
if [ $# -eq 3 ]; then
ans=$(( $n1 $op $n2 ))
echo "$n1 $op $n2 = $ans"
return $ans
else
echo "Function cal requires atleast three args"
fi
return
}
cal 5 + 10
cal 10 - 2
cal 10 / 2
echo $?
Run result:
$ ./pass1
5 + 10 = 15
10 - 2 = 8
10 / 2 = 5
5
My question is:
why it is: ans=$(( $n1 $op $n2 ))
not: ans=( $n1 $op $n2 ) ***
I tried the *** one: the running result is:
5 + 10 = 5
10 - 2 = 10
10 / 2 = 10
10
can any exlain a little bit?
Thank you very much
s