From 5c6dca34ef54daf8ca83102aa02c0e382ddea2c2 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 13 Jun 2018 13:27:38 +1000 Subject: [PATCH] docs: update --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 8177c8b..2dd4d44 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ scripts and not full blown utilities. * [Get the last N lines of a file.](#get-the-last-n-lines-of-a-file) * [Get the number of lines in a file.](#get-the-number-of-lines-in-a-file) * [Strings](#strings) + * [Trim white-space from string.](#trim-white-space-from-string) * [Split a string on a delimiter.](#split-a-string-on-a-delimiter) * [Change a string to lowercase.](#change-a-string-to-lowercase) * [Change a string to uppercase.](#change-a-string-to-uppercase) @@ -117,6 +118,21 @@ lines() { ## Strings +### Trim white-space from string. + +**NOTE**: This also truncates multiple spaces inside the string. + +```sh +# shellcheck disable=SC2086,SC2048 +trim() { + # Usage: trim " example string " + set -f + set -- $* + printf '%s\n' "$*" + set +f +} +``` + ### Split a string on a delimiter. ```sh