From d5b19a5f2a25b07340713b107e4548a35dc8f5dc Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Wed, 13 Jun 2018 13:42:29 +1000 Subject: [PATCH] docs: update --- README.md | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a65e601..018d480 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,8 @@ scripts and not full blown utilities. * [Change a string to lowercase.](#change-a-string-to-lowercase) * [Change a string to uppercase.](#change-a-string-to-uppercase) * [Trim quotes from a string.](#trim-quotes-from-a-string) + * [Strip characters from start of string.](#strip-characters-from-start-of-string) + * [Strip characters from end of string.](#strip-characters-from-end-of-string) * [Arrays](#arrays) * [Reverse an array.](#reverse-an-array) * [File Paths](#file-paths) @@ -189,6 +191,24 @@ trim_quotes() { } ``` +### Strip characters from start of string. + +```sh +lstrip() { + # Usage: lstrip "string" "chars to remove" + printf '%s\n' "${1##$2}" +} +``` + +### Strip characters from end of string. + +```sh +rstrip() { + # Usage: rstrip "string" "chars to remove" + printf '%s\n' "${1%%$2}" +} +``` + ## Arrays ### Reverse an array. @@ -228,8 +248,8 @@ Alternative to the `basename` command. ```sh basename() { # Usage: basename "path" - path="${1%/}" - printf '%s\n' "${path##*/}" + : "${1%/}" + printf '%s\n' "${_##*/}" } ```