Skip to content

Instantly share code, notes, and snippets.

@depressed-pho
Created April 17, 2012 07:44
Show Gist options
  • Save depressed-pho/2404239 to your computer and use it in GitHub Desktop.
Save depressed-pho/2404239 to your computer and use it in GitHub Desktop.
Fibonacci series in /bin/sh
#!/bin/sh
fibonacci_init() {
_fib_0=1
_fib_1=1
_fib_2=1
_fib_n=0
}
fibonacci_next() {
case $_fib_n in
0|1)
echo $_fib_2
_fib_n=`expr $_fib_n + 1`
;;
*)
_fib_2=`expr $_fib_0 + $_fib_1`
echo $_fib_2
_fib_0=$_fib_1
_fib_1=$_fib_2
;;
esac
}
fibonacci_init
while true; do
fibonacci_next
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment