10
rated 0 times
[
10]
[
0]
/ answers: 1 / hits: 6125
/ 2 Years ago, sun, september 4, 2022, 11:12:06
I am trying to get the word count of a string using the wc
command. But it gives me a different answer. It increases the number of words by 1.
This is the code:
echo Enter a string:
read str
len=`echo $str | wc -c`
echo you have entered: $str
echo and the word count: $len
The output is like this:
Enter a string:
robin
you have entered: robin
and word count: 6
What am I doing wrong? Please help me solve this. I will be very grateful. Thank you.
More From » command-line