Calculating variable sizes with bash


While perusing the bash documentation today I came across the ${#} built-in, which can be used to view the size of a variable:

$ foo="some number of characters"

$ echo {#foo}
25

This could be useful for iterating through strings in a loop, and is now part of my shell programming crib notes. Niiiiiiiiiiiiiiiiice!

This article was posted by Matty on 2006-02-12 15:08:00 -0400 -0400