gibibytes_to_bytes() { echo $(( 1024 * 1024 * 1024 * "${1}" )) } mebibytes_to_bytes() { echo $(( 1024 * 1024 * "${1}" )) } kibibytes_to_bytes() { echo $(( 1024 * "${1}" )) } bytes_to_gibibytes() { echo $(( "${1}" / 1024 / 1024 / 1024 )) } to_bytes() { case "${1: -1}" in b) echo "${1:0: -1}" ;; [0-9]) echo "${1}" ;; K) kibibytes_to_bytes "${1:0: -1}" ;; M) mebibytes_to_bytes "${1:0: -1}" ;; G) gibibytes_to_bytes "${1:0: -1}" ;; *) fatal UNIT_E "${1:-1} is not a valid unit" ;; esac }