Search code examples
bashstring-length

Bash compare if two strings match by length


I have two string variables that I need to compare by length inside of if. So I need to do something like this:

if [ length($string_one) != length($string_two) ]:

fi

Solution

  • if [[ ${#string} != ${#string_two} ]]; then
        run command
    fi