From 38ba5a290c5ae915bbb395f53116275c18da7f2a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 11 Oct 2016 02:49:23 +0300 Subject: add str_tolower, str_toupper, str_contains --- %HOME%/.bash_utils/text.sh | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to '%HOME%') diff --git a/%HOME%/.bash_utils/text.sh b/%HOME%/.bash_utils/text.sh index 1ce36a6..4ecffd6 100644 --- a/%HOME%/.bash_utils/text.sh +++ b/%HOME%/.bash_utils/text.sh @@ -41,3 +41,36 @@ replace_word() ( sed --binary --in-place "s/\\b$old\\b/$new/g" "$@" ) + +str_tolower() ( + set -o errexit -o nounset -o pipefail + + local s + for s; do + echo "${s,,}" # | tr '[:upper:]' '[:lower:]' + done +) + +str_toupper() ( + set -o errexit -o nounset -o pipefail + + local s + for s; do + echo "${s^^}" # | tr '[:lower:]' '[:upper:]' + done +) + +str_contains() ( + set -o errexit -o nounset -o pipefail + + if [ "$#" -ne 2 ]; then + echo "usage: ${FUNCNAME[0]} STR SUB" + return 1 + fi + + local str="$1" + local sub + sub="$( printf '%q' "$2" )" + + test "$str" != "${str#*$sub}" +) -- cgit v1.2.3