Shell variables are always considered as string, unless they contain only digits and are used within an arithmetic comparison or operation. Indeed, they are generally un-typed. Nevertheless you can use the
declare function in bash to assign a type. Regarding the length of the string, the statements below are equivalent:
Code:
${#string}
expr length $string
expr "$string" : '.*'
the last of them is the "classic" UNIX-style
expr command to retrieve the length of $string. Bash introduced the ${#string} notation. You will find these explanations and a lot more on the
Advanced Bash-Scripting Guide. A must reading!