scripts

My personal collection of scripts
git clone git://src.gearsix.net/scripts
Log | Files | Refs | Atom | README | LICENSE

commit 5555668bb24285fd1a65032ead3bd56fbcf46deb
parent 14a66325f7d03abb566a2c47c2a0b984651f53c1
Author: gearsix <gearsix@tuta.io>
Date:   Mon, 26 Jul 2021 16:25:01 +0100

depreciated strlen

Diffstat:
Asrc/depreciated/strlen.sh | 28++++++++++++++++++++++++++++
Dsrc/strlen.sh | 21---------------------
2 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/src/depreciated/strlen.sh b/src/depreciated/strlen.sh @@ -0,0 +1,28 @@ +#!/bin/sh +# strlen (string length) +# description: echo's the length of a string ($1) +# e.g.$ strlen "ma di-" +# +# SEE: https://stackoverflow.com/questions/17368067/length-of-string-in-bash + +if [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + echo "Usage: strlen STRING" + echo "" + echo "print the number of characters and bytes for each word in STRING" + exit +fi + +strU8DiffLen () { + local bytlen oLang=$LANG oLcAll=$LC_ALL + LANG=C LC_ALL=C + bytlen=${#1} + LANG=$oLang LC_ALL=$oLcAll + return $(( bytlen - ${#1} )) +} + +for string in $@; do + strU8DiffLen "$string" + printf "%-$((14+$?))s is %2d chars length and uses %2d bytes\n" \ + "'$string'" ${#string} $((${#string}+$?)) +done + diff --git a/src/strlen.sh b/src/strlen.sh @@ -1,21 +0,0 @@ -#!/bin/sh -# strlen (string length) -# description: echo's the length of a string ($1) -# e.g.$ strlen "ma di-" -# -# SEE: https://stackoverflow.com/questions/17368067/length-of-string-in-bash - -strU8DiffLen () { - local bytlen oLang=$LANG oLcAll=$LC_ALL - LANG=C LC_ALL=C - bytlen=${#1} - LANG=$oLang LC_ALL=$oLcAll - return $(( bytlen - ${#1} )) -} - -for string in $@; do - strU8DiffLen "$string" - printf "%-$((14+$?))s is %2d chars length and uses %2d bytes\n" \ - "'$string'" ${#string} $((${#string}+$?)) -done -