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

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!