Shell

Shell

Made by DeepSource

Consider using ${#variable} SH-2000

Anti-pattern
Minor

Consider using ${#variable} to get the number of characters in a 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:

#!/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