]> git.ipfire.org Git - people/ms/network.git/commitdiff
util: add normalize function
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Fri, 18 Aug 2017 11:45:18 +0000 (13:45 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Aug 2017 12:55:51 +0000 (14:55 +0200)
This function remove all non alpha numerical characters from a string
and substitute this characters with one -

So HELLO%%/$&/)%$%(&&HH becomes hello-hh

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

index f096fbb79cac8e8e6ad99abfde7cf829b64ffce8..dff0b90789183a5242392456660708a9d4f01ab8 100644 (file)
@@ -850,3 +850,9 @@ copy() {
                return ${EXIT_ERROR}
        fi
 }
+
+normalize() {
+       local string="$@"
+
+       tr -sc [:alnum:] "-" < <(printf "%s" "${string,,}")
+}