#!/bin/sh # Prints the string length in both characters and bytes (unicode # characters can be multi-byte. # Also prints an escaped version of the string. me=`basename "$0"` if [ "$#" -ne 1 ]; then echo "usage: $me string" exit fi langbak=$LANG LANG=C bytlen=${#1} printf -v sreal %q "$1" LANG=$langbak printf "%d bytes, %d chars: %s\n." $bytlen ${#1} "$sreal"