Solved

Counting charcters

Posted on 2001-06-07
2
230 Views
Last Modified: 2010-04-21
Hi all,

I am learning shell scripts. I need to do some
validations. TO do that I need to count the chars in a
given word. Could you help me in that ?

1) Accept the word from user ( I can do this :))

2) count the characters in the given word and store the
number in a variable.

3) Display the content of the variable ?

wc -c counts including end of the line or word char. How
to avoid this ?

I am using sun solaris 5.8


Thanks in advance
Gururaj
0
Comment
Question by:reach_gururaj
2 Comments
 
LVL 6

Accepted Solution

by:
bira earned 50 total points
ID: 6164491
Hi
   Save this script

   echo "accept a word"
   read word
   c=`echo $word |wc -c`
   count=`expr $c - 1`
   echo "Lenght of the word:" $count

   chmod it to 777 and run
0
 

Author Comment

by:reach_gururaj
ID: 6164920
Thanks bira.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
nodeip 9 86
Write an app 10 70
Linux hostname change 2 83
Expiration and Locking of Unix/Solaris OS Accounts 7 49
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question