From: Michael Gebetsroither Date: Tue, 18 Apr 2006 12:19:17 +0000 (+0200) Subject: added stringTrim function to trim off white-space characters X-Git-Tag: grml0.9 X-Git-Url: http://git.grml.org/?p=grml-shlib.git;a=commitdiff_plain;h=ca40690faf40a28d31777061d5055e55d7e8b0cd added stringTrim function to trim off white-space characters --- diff --git a/sh-lib b/sh-lib index 85d3c56..5d0ac5b 100644 --- a/sh-lib +++ b/sh-lib @@ -370,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 {