Last active
March 8, 2020 15:45
-
-
Save a60814billy/4fd114c860b715c86c8dffc8997f1c62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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