Created
September 4, 2020 13:00
-
-
Save bitmvr/a6cca248c49370b7c0d3a043d093e29f to your computer and use it in GitHub Desktop.
Calculate Percentage of Change
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
#!/usr/bin/env bash | |
usage(){ | |
echo "$(basename "$0") start_value end_value" | |
} | |
# Check if any flags or values were passed | |
if [ "$#" -eq 0 ]; then | |
usage | |
exit | |
fi | |
# If the flag for help is passed, display usage | |
case "$1" in | |
-h|--help) | |
usage | |
exit | |
;; | |
esac | |
start_value="$1" | |
end_value="$2" | |
scale_value="4" | |
value="$(bc -l <<< "scale=${scale_value}; ${end_value} - ${start_value}")" | |
value="$(bc -l <<< "scale=${scale_value}; ${value} / ${start_value}")" | |
value="$(bc -l <<< "scale=${scale_value}; ${value} * 100")" | |
echo "${value}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment