Solved

Counting charcters

Posted on 2001-06-07
2
227 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
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…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now