25 October 2012

Find the length of the String in Bash

1 comment

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 $word | wc -c
23

Enjoy :)


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

1 comment: