Files
dotfiles/utils/.local/bin/len
2026-02-21 18:10:09 +08:00

25 lines
436 B
Bash
Executable File

#!/usr/bin/env bash
set -eo pipefail
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
cat <<EOF
Usage: $(basename "$0") [-h] <string>
Display length of a string.
Options:
-h, --help Show this help message
Arguments:
string String to measure
EOF
exit 0
fi
if [[ ! -t 0 ]]; then # Read from stdin (pipe)
wc -c | awk '{print $1}'
else # Read from arguments
echo -n "$@" | wc -c | awk '{print $1}'
fi