Thursday, October 25, 2012
9:28 PM

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