I am writing a shell script command which counts the characters typed.
I am using wc
. My script is echo $1 | wc -c
. The problem is that it is counting a +1 character. For example, if i type 'hello' it displays (6) characters typed but it should display (5). Any ideas on how I can solve this problem?
Asked
Active
Viewed 216 times
0

cmd
- 11,622
- 7
- 51
- 61

hello world
- 1
- 1
1 Answers
0
Depending on the shell you're using, you could do this:
$ var='hello'
$ echo ${#var}
5
This way you don't need to call an external program.

jwk
- 1
-
echo $1 | wc -L what this does is, it Prints the maximum line length. – hello world Oct 05 '13 at 00:01