# How to count the string length

**URL:** <https://community.unix.com/t/how-to-count-the-string-length/162505>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [June 15, 2006, 1:21am UTC](https://community.unix.com/t/how-to-count-the-string-length/162505 "2006-06-15T01:21:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anshu](https://community.unix.com/letter_avatar/anshu/32/6_22734026db12803ebb3e059622ac3534.png) [@Anshu](https://community.unix.com/u/Anshu)\
**Post date:** [June 15, 2006, 1:21am UTC](https://community.unix.com/t/how-to-count-the-string-length/162505/1 "2006-06-15T01:21:59Z")

</div>

Please can anyone tell me, how to count the string length

---

<div class="post-metadata">

**Author:** ![vino](https://community.unix.com/user_avatar/community.unix.com/vino/32/156_2.png) [@vino](https://community.unix.com/u/vino)\
**Post date:** [June 15, 2006, 1:31am UTC](https://community.unix.com/t/how-to-count-the-string-length/162505/2 "2006-06-15T01:31:28Z")

</div>

One way is to assign it to a variable. And then do ${#variable}. The other would be to traverse through the string and keep a count.

---

<div class="post-metadata">

**Author:** ![grial](https://community.unix.com/user_avatar/community.unix.com/grial/32/379_2.png) [@grial](https://community.unix.com/u/grial)\
**Post date:** [June 15, 2006, 3:32am UTC](https://community.unix.com/t/how-to-count-the-string-length/162505/3 "2006-06-15T03:32:24Z")

</div>

Another is using "wc" though I think it also couts "return char"...  
For instance, in AIX with bash:  
echo helo | wc -m  
returns 5  
echo -e "helo\c" | wc -m  
returns 4
