Thursday, October 25, 2012

Find the length of the String in Bash

Q: How do I find the length of the String in Bash
Ans: There are number of ways to find the length of the String in Bash.

Method 1:

$ word="technical world for you"
$ echo "${#word}"
23

Method 2:

$ word="technical world for you"
$ expr length "$word"
23
Method 3:

$ word="technical world for you"
$ echo $word | awk '{print length}'
23
Method 4:

$ word="technical world for you"
$ echo -n $

0 comments:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.