Created
December 11, 2017 21:14
-
-
Save thikade/a86b860070f740bea19a0de74d44a255 to your computer and use it in GitHub Desktop.
bash regex
This file contains hidden or 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
# INSTANCE_RAM examples | |
# INSTANCE_RAM=8G or INSTANCE_RAM=12m | |
regex='^([[:digit:]]+)([GgMm])$' | |
if [[ "${INSTANCE_RAM}" =~ $regex ]]; then | |
num=${BASH_REMATCH[1]} | |
unit=${BASH_REMATCH[2]} | |
if [[ $unit =~ [Gg] ]]; then | |
((num = num * 1024)) # enables math to work out for odd gigs | |
fi | |
if [[ $num -lt 512 ]]; then | |
echo "INSTANCE_RAM set to ${INSTANCE_RAM} but must be at least 512M" | |
exit 1 | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment