4 SC2000
Joachim Ansorg edited this page 2021-11-12 19:13:36 +01:00

See if you can use ${#variable} instead

${#variable} will be equal to the number of characters in "${variable}"

This is the same result as "$( echo "$variable" | wc -m )" When "$variable" only contains single-byte characters, it's also the same as "$( echo "$variable" | wc -c )"

example code

#!/usr/bin/env  bash

if [ "$( echo "$1" | wc -c )" -gt 1 ]; then
  echo "greater than 1"
fi

if [ "$( echo "$1" | wc -m )" -gt 1 ]; then
  echo "greater than 1"
fi

if [ "${#1}" -gt 1 ]; then
  echo "greater than 1"
fi