Get the length of a variable value as follows:
length=${#var}
For example:
$ var=linuxrecipes.com $ echo ${#var} 16
length is the number of characters in the string.
Source: Linux Shell Scripting Cookbook
Subscribe to our e-mail newsletter to receive updates.
bash, shell, string, tips, variables