Added HumanToNumeric function
This commit is contained in:
parent
a450cf39d0
commit
97a1db5f55
|
@ -1,6 +1,6 @@
|
||||||
#### MINIMAL-FUNCTION-SET BEGIN ####
|
#### MINIMAL-FUNCTION-SET BEGIN ####
|
||||||
|
|
||||||
## FUNC_BUILD=2016102203
|
## FUNC_BUILD=2016102301
|
||||||
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
## BEGIN Generic bash functions written in 2013-2016 by Orsiris de Jong - http://www.netpower.fr - ozy@netpower.fr
|
||||||
|
|
||||||
## To use in a program, define the following variables:
|
## To use in a program, define the following variables:
|
||||||
|
@ -902,6 +902,34 @@ function IsInteger {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Converts human readable sizes into integer kilobyte sizes
|
||||||
|
function HumanToNumeric {
|
||||||
|
local notation
|
||||||
|
local suffix
|
||||||
|
local suffixPresent
|
||||||
|
local multiplier
|
||||||
|
|
||||||
|
notation=(K M G T P E)
|
||||||
|
for suffix in "${notation[@]}"; do
|
||||||
|
multiplier=$((multiplier+1))
|
||||||
|
if [[ "$disk_space" == *"$suffix"* ]]; then
|
||||||
|
suffixPresent=$suffix
|
||||||
|
break;
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ "$suffixPresent" != "" ]; then
|
||||||
|
disk_space=${disk_space%$suffix*}
|
||||||
|
disk_space=${disk_space%.*}
|
||||||
|
# /1024 since we convert to kilobytes instead of bytes
|
||||||
|
disk_space=$((disk_space*(1024**multiplier/1024)))
|
||||||
|
else
|
||||||
|
disk_space=${disk_space%.*}
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo $disk_space
|
||||||
|
}
|
||||||
|
|
||||||
## from https://gist.github.com/cdown/1163649
|
## from https://gist.github.com/cdown/1163649
|
||||||
function urlEncode {
|
function urlEncode {
|
||||||
local length="${#1}"
|
local length="${#1}"
|
||||||
|
|
Loading…
Reference in New Issue