summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'functions.sh')
-rw-r--r--functions.sh16
1 files changed, 16 insertions, 0 deletions
diff --git a/functions.sh b/functions.sh
index 1548bd0..30c2447 100644
--- a/functions.sh
+++ b/functions.sh
@@ -514,6 +514,22 @@ srandom()
}
#
+# Trims leading and trailing whitespace from one or more lines. If at least one
+# parameter is provided, each positional parameter shall be considered as a line
+# to be processed. Otherwise, the lines to be processed shall be read from the
+# standard input. The trimmed lines shall be printed to the standard output.
+#
+trim()
+{
+ if [ "$#" -gt 0 ]; then
+ printf '%s\n' "$@"
+ else
+ cat
+ fi |
+ sed -e 's/^[[:space:]]\{1,\}//' -e 's/[[:space:]]\{1,\}$//'
+}
+
+#
# Prints a diagnostic message prefixed with the basename of the running script.
#
warn()