aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-11 02:49:23 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-11 02:49:23 +0300
commit38ba5a290c5ae915bbb395f53116275c18da7f2a (patch)
tree7757761f786ba65e975992d7765a187b7ed824c4 /%HOME%
parentgpg.conf: minimize (diff)
downloadlinux-home-38ba5a290c5ae915bbb395f53116275c18da7f2a.tar.gz
linux-home-38ba5a290c5ae915bbb395f53116275c18da7f2a.zip
add str_tolower, str_toupper, str_contains
Diffstat (limited to '')
-rw-r--r--%HOME%/.bash_utils/text.sh33
1 files changed, 33 insertions, 0 deletions
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}"
+)