here is the shell script:
#!/bin/bash
version="0.01";
fibonacci() {
n=${1:?If you want the nth fibonacci number, you must supply n as the first parameter.}
if [ $n -le 1 ]; then
echo $n
else
l=`fibonacci $((n-1))`
r=`fibonacci $((n-2))`
echo $((l + r))
fi
}
for i in `seq 1 10`
do
result=$(fibonacci $i)
echo "i=$i result=$result"
done
And i come to confused about this line:
n=${1:?If you want the nth fibonacci number, you must supply n as the first parameter.}
i look for the manual of shell,but get nothing about what does the “:?” actually mean.
thx
from man bash:
in this case the parameter being checked is $1 (the first positional parameter)