Bash: Command to Find the Length of a String


If you are on the bash shell and want to know what is the length of a string, then you can make use of the wc command.


Example:

bash-3.2$ echo -n "This is my string" | wc -c

      17

We need the -n flag or else a new-line character will get added to the length.

Bash Command to Find Length of a String in Terminal

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap