Differences between revisions 1 and 2
Revision 1 as of 2007-05-02 22:51:12
Size: 484
Editor: redondos
Comment:
Revision 2 as of 2008-11-22 14:08:37
Size: 484
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
[[Anchor(faq7)]] <<Anchor(faq7)>>
Line 3: Line 3:
The fastest way, not requiring external programs (but usable only with ["BASH"] and KornShell): The fastest way, not requiring external programs (but usable only with [[BASH]] and KornShell):
Line 22: Line 22:
(for a BSD/GNU version of {{{expr}}}. Do not use this, because it is not ["POSIX"]). (for a BSD/GNU version of {{{expr}}}. Do not use this, because it is not [[POSIX]]).

Is there a function to return the length of a string?

The fastest way, not requiring external programs (but usable only with BASH and KornShell):

${#varname}

or

expr "$varname" : '.*'

(expr prints the number of characters matching the pattern .*, which is the length of the string)

or

expr length "$varname"

(for a BSD/GNU version of expr. Do not use this, because it is not POSIX).

BashFAQ/007 (last edited 2015-03-05 00:24:26 by izabera)