Monday, September 29, 2008

Shell String Operations: How to get length of a string

To get length of string in Unix shell, use the following command
${#varname}
where varname is name of the variable that contains the string
or you can also use command
expr length $varname

Example:
varname='Shoma'
expr length $varname
# Returns 5

No comments:

Post a Comment