blob: 3a8d15a07461bf4c4648e58aa30f9aa40dc867d2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#!/usr/bin/env zsh
# convert bits to human-readable value
local suffixes=( 'B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y' )
local sindex=1
local val=$1
[[ -z $(echo $1 | grep "^[0-9]*$") ]] && read val
while [[ $(echo $val / 1024 | bc) -ne 0 ]]; do
val=$(echo "scale=2; $val / 1024" | bc)
let sindex=sindex+1
done
echo "${val}${suffixes[$sindex]}"
|