🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1444

Counting characters in a string...bourne

#1444
From: Dave Taylor {guest}
Date: Tue, 09 Oct 1990 16:55
46 lines
1831 bytes
First off:

I am trying to count the number of characters in a string, but I seem to
be running into problems.  I tried:
	echo $STRING | wc | awk '{ print $3 }'
the only problem with this is that it drops spaces.  I want to count ALL
the characters.  I suppose I could just adapt some of the awk scripts that
have been flying on the newsgroups lately, but I was looking for something
clean and simple.

Secondly:

WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY -- WHY ??

Why does the following string get pushed together??

Script:
TITLE="This              is some text"
echo "$TITLE"

Output:
This is some text

How to I keep it from being pushed together??


THIRDLY:

The point of all this is to be able to center a header with pwd in it.  So that
is says something like:

program 1.1			Check to see foo.bar			/u/user

I need to count the spaces between bar and EOL as well as the length of the pwd
string.  A while loop using expr to count takes an eternity.  What could make
it faster???

Thanks in advance,


--david
-- 
-------                                                                 -------
David E. Taylor, OMSS UNIX Development // Operation Mobilization USA
AT&T: (404) 631-0432  +====+  UUCP:    {decvax, sun!sunatl, gatech}!emory!om!dt
FAX:  (404) 631-0439  +====+  Internet: dt%om.uucp@mathcs.emory.edu
Technical Details
Message-ID: <6383@emory.mathcs.emory.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!ogicse!emory!dt

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!uwm.edu!ogicse!emory!dt
From: dt@mathcs.emory.edu (Dave Taylor {guest})
Newsgroups: comp.unix.shell
Subject: Counting characters in a string...bourne
Summary: counting characters in a script, dropping spaces, adding blanks
Message-ID: <6383@emory.mathcs.emory.edu>
Date: 9 Oct 90 16:55:55 GMT
Distribution: usa
Organization: Emory University, Dept of Math and CS
Lines: 46