I have a BASH script named fib.sh. The script reads a user input (number) and performs a calculation. I want to be able to type
$ ./fib.sh 8
where 8 is the input
Currently, I have to wait for the next line to enter the input.
$ ./fib.sh
$ 8
Script
#!/bin/bash
read n
a=0
b=1
count=1
fib=$a
while [ $count -lt $n ];
do
fib=$[$a+$b]
a=$b
b=$fib
count=$[$count+1]
done
echo "fib $n = $fib"
exit 0
$[…]is deprecated; use$((…))(part of the POSIX standard) instead. Examplefib=$(($a+$b)).$inside:$((a+b)).