]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Add quote and unquote functions.
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Oct 2012 12:48:03 +0000 (12:48 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 8 Oct 2012 12:48:03 +0000 (12:48 +0000)
functions.config
functions.util

index 9a50de66d5cdf99357677767c5bd0178ca6f9b31..8e1ab95d0139a3a67a78cc29ff895fc64487e589 100644 (file)
@@ -113,16 +113,7 @@ function config_strip() {
                return ${EXIT_OK}
        fi
 
-       if [ "${var:0:1}" = "\"" ]; then
-               var=${var:1}
-       fi
-
-       local last=$(( ${#var} - 1 ))
-       if [ ${last} -ge 0 ] && [ "${var:${last}:1}" = "\"" ]; then
-               var=${var:0:${last}}
-       fi
-
-       print "${var}"
+       unquote "${var}"
 }
 
 function config_write() {
index 96b83b5156dc0a0c24b7d1c56733f511cedf8501..68fac1b39fc71f48e2d719eea823890864921a8b 100644 (file)
@@ -33,6 +33,25 @@ function args() {
        echo "$@" | xargs printf "%s\n"
 }
 
+function unquote() {
+       local var="$@"
+
+       if [ "${var:0:1}" = "\"" ]; then
+               var=${var:1}
+       fi
+
+       local last=$(( ${#var} - 1 ))
+       if [ ${last} -ge 0 ] && [ "${var:${last}:1}" = "\"" ]; then
+               var=${var:0:${last}}
+       fi
+
+       print "${var}"
+}
+
+function quote() {
+       print "\"%s\"" "$@"
+}
+
 # Print a pretty error message
 function error() {
        echo -e " ${CLR_RED_B}ERROR${CLR_RESET}  : $@" >&2