2
0
mirror of https://github.com/deajan/osync synced 2024-11-03 15:40:14 +00:00

Added HumanToNumeric function

This commit is contained in:
deajan 2016-10-23 10:35:38 +02:00
parent a450cf39d0
commit 97a1db5f55

View File

@ -1,6 +1,6 @@
#### 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
## To use in a program, define the following variables:
@ -902,6 +902,34 @@ function IsInteger {
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
function urlEncode {
local length="${#1}"