Search code examples
bashshellstring-length

Bash increment length of string


I just want to echo an incremented string length. For example:

STR="test"
echo ${#STR}

It prints 4, but I want to print 5.


Solution

  • STR="test"
    count=${#STR}
    ((count++))
    echo $count
    

    ((count++)): How to increment a variable in bash?