Skip to content

Instantly share code, notes, and snippets.

@a60814billy
Last active March 8, 2020 15:45
Show Gist options
  • Save a60814billy/4fd114c860b715c86c8dffc8997f1c62 to your computer and use it in GitHub Desktop.
Save a60814billy/4fd114c860b715c86c8dffc8997f1c62 to your computer and use it in GitHub Desktop.
#!/bin/bash
# usage:
# ./fibvalid.sh numberOfFib actualNumber
# example:
# ./fibvalid.sh 10 55
# ok, fib(10) = 55
# ./fibvalid.sh 10 54
# fail, fib(10) = 55, not 54
set -euo pipefail
EXPECT="$(curl -s http://www.protocol5.com/Fibonacci/$1.htm | grep -oP 'Decimal\s+Base\s+10.*<div>\K\d+')"
if [[ -z "$EXPECT" ]]; then
echo "fail to fetch fibonacci number from http://www.protocol5.com/Fibonacci/$1.htm"
exit 2;
fi
if [[ "$EXPECT" != "$2" ]]; then
echo "fail, fib($1) = $EXPECT, not $2"
exit 1;
fi
echo "ok, fib($1) = $EXPECT"
exit 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment