]> git.ipfire.org Git - people/stevee/network.git/commitdiff
util: Add some helper functions: fread, fwrite, assign.
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 29 Sep 2012 12:43:01 +0000 (12:43 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 29 Sep 2012 12:43:01 +0000 (12:43 +0000)
functions.util

index a74935398d2104581ac6c86d4b3722b5975b7c88..96b83b5156dc0a0c24b7d1c56733f511cedf8501 100644 (file)
@@ -70,6 +70,31 @@ function basename() {
        echo "${1##*/}"
 }
 
+function assign() {
+       local key=${1}
+       assert isset key
+       shift
+
+       printf -v "${key}" "%s" "$@"
+}
+
+function fread() {
+       local file=${1}
+       assert isset file
+
+       [ -r "${file}" ] || return ${EXIT_ERROR}
+
+       print "$(<${file})"
+}
+
+function fwrite() {
+       local file=${1}
+       assert isset file
+       shift
+
+       print "%s" "$@" >> ${file}
+}
+
 function enabled() {
        local param=${1}