Created
May 15, 2017 15:07
-
-
Save damc-dev/d1b433052e70e9556243a36104714298 to your computer and use it in GitHub Desktop.
Convert a value provided to the JVM to Kb
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
#!/bin/bash | |
convertToKb() { | |
data="$1" | |
unit="${data//[0-9]/}" | |
value="${data//[!0-9]}" | |
converted="ERROR" | |
case $unit in | |
k | K) | |
converted="$value" | |
;; | |
m | M) | |
converted=$(echo "scale=2; $value * 1024" | bc) | |
;; | |
g | G) | |
converted=$(echo "scale=2; $value * 1024 * 1024" | bc) | |
;; | |
*) | |
converted="$data" | |
;; | |
esac | |
echo "$converted" | |
} | |
result="$(convertToKb $1)" | |
echo $result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment