From: Michael Tremer Date: Sat, 29 Sep 2012 12:43:01 +0000 (+0000) Subject: util: Add some helper functions: fread, fwrite, assign. X-Git-Tag: 005~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b79ad79b1e92e59790f6403a14e5d281d5f2135f;p=network.git util: Add some helper functions: fread, fwrite, assign. --- diff --git a/functions.util b/functions.util index a7493539..96b83b51 100644 --- a/functions.util +++ b/functions.util @@ -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}