Bash: Finding length of string

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

Subscribe to our e-mail newsletter to receive updates.

, , , ,