Click to See Complete Forum and Search --> : Need help for a shell script (bash)
-Stalker-
11-28-2000, 05:25 PM
I'm writing a bash script and need this:
I have a text variable, $text for example.
text='Don't eat me baby :)'
What I should do to know the length of this variable, I mean the count of symbols?
[This message has been edited by -Stalker- (edited 28 November 2000).]
The King Ant
11-28-2000, 06:08 PM
If you have wc (word count) installed, you can run "wc -l filename"... Maybe you could echo the variable to a file in /tmp? I realize that this is ugly and slow and dumb. But it works...
Maybe you could cat a newline character on the end of the string, then loop through and count char by char until you hit the newline? Then take the newline off? I guess this isn't all that smooth either though...
-Stalker-
11-28-2000, 06:57 PM
I found!
count=`expr "$text" : '.*'`
heh, this is really works and fast enough
but... if you will have any better stuff that will work faster than mine... I'm waiting for it!
Thanks!!
[This message has been edited by -Stalker- (edited 28 November 2000).]
[This message has been edited by -Stalker- (edited 28 November 2000).]
Strike
11-28-2000, 08:13 PM
count=`expr length $MY_VAR`
works for me