Skip to content

Instantly share code, notes, and snippets.

@damc-dev
Created May 15, 2017 15:07
Show Gist options
  • Save damc-dev/d1b433052e70e9556243a36104714298 to your computer and use it in GitHub Desktop.
Save damc-dev/d1b433052e70e9556243a36104714298 to your computer and use it in GitHub Desktop.
Convert a value provided to the JVM to Kb
#!/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