added stringTrim function to trim off white-space characters
[grml-shlib.git] / sh-lib
diff --git a/sh-lib b/sh-lib
index e68951c..5d0ac5b 100644 (file)
--- a/sh-lib
+++ b/sh-lib
@@ -177,6 +177,10 @@ function warnLog
 #
 ###
 
+##
+# ATTENTION... THIS FUNCTINOS IS A BIG SECURITY HOLE
+# this function will be changed in future release
+##
 # i don't want to write exit status controle stuff every time
 function execute
 {
@@ -186,6 +190,7 @@ function execute
 
   local ret_=''
 
+  # NOT A GOOD IDEA
   eval "$to_exec_"
   ret_=$?
 
@@ -246,7 +251,7 @@ function isNotExistent
 
   if [ -e "$file_to_test_" ]; then
     if [ -z "$message_" ]; then
-      $error_function_ "file does allready exist \"$file_to_test_\"" 67
+      $error_function_ "file does already exist \"$file_to_test_\"" 67
     else
       $error_function_ "$message_"
     fi
@@ -365,6 +370,26 @@ function relToAbs
   echo "$abspath_"
 }
 
+
+# Trim off white-space characters
+# white-space in the "C" and "POSIX" locales are:
+#   space
+#   form-feed ('\f')
+#   newline ('\n')
+#   carriage return ('\r')
+#   horizontal tab ('\t')
+#   vertical tab ('\v')
+function stringTrim
+{
+  local str_="$1"
+  local result_=""
+
+  result_="`echo "$str_" | sed -e 's/^\s*//' -e 's/\s*$//'`" || \
+    warn "stringTrim(): Problems stripping of blanks" || return 1
+  dprint "stringTrim(): \"$str_\" => \"$result_\""
+  echo "$result_"
+}
+
 # Simple shell grep
 function stringInFile
 {