diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-11 02:49:23 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-10-11 02:49:23 +0300 |
commit | 38ba5a290c5ae915bbb395f53116275c18da7f2a (patch) | |
tree | 7757761f786ba65e975992d7765a187b7ed824c4 /%HOME%/.bash_utils | |
parent | gpg.conf: minimize (diff) | |
download | linux-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.sh | 33 |
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}" +) |