]> git.ipfire.org Git - people/stevee/network.git/commitdiff
util: new function abs
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Fri, 9 Jun 2017 10:17:27 +0000 (12:17 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 14 Jun 2017 20:43:42 +0000 (22:43 +0200)
This function return the absolute value of a given number.

Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.util

index b7e35c91e063814fc9301dd04a474ed0d6346b60..37feb73b308a4e0b7c23a3184de9dc0e2a3f7e8e 100644 (file)
@@ -268,6 +268,16 @@ uuid() {
        echo $(</proc/sys/kernel/random/uuid)
 }
 
+abs() {
+       local val=${1}
+
+       if [ ${val} -lt 0 ]; then
+               (( val *= -1 ))
+       fi
+
+       echo ${val}
+}
+
 rand() {
        local uuid="$(uuid)"
        echo "${uuid//-/}"