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}" ;; S) sectors_to_bytes "${1:0: -1}" ;; *) fatal UNIT_E "${1:-1} is not a valid unit" ;; esac } bytes_to_sectors() { echo $(( "${1}" / 512 )) } to_sectors() { bytes_to_sectors $( to_bytes "${1}" ) } sectors_to_gibibytes() { echo $(bytes_to_gibibytes $(sectors_to_bytes "${1}")) } sectors_to_bytes() { echo $(( 512 * "${1}" )) }