Count Characters

Count the number of characters in a string, with option to exclude spaces.

Code

General
[ "$includeSpaces" = "true" ] && echo ${#str} || echo "${str// /}" | wc -c | tr -d ' '

Parameters

The string to count characters in

Whether to include spaces in the count

Server

More Bash Snippets