#!/usr/bin/env bash set -eo pipefail if [[ "$1" == "-h" || "$1" == "--help" ]]; then cat < 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