The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find the string length in solaris din_annauniv Shell Programming and Scripting 4 06-20-2008 07:43 AM
Awk:Find length of string omitting quotes jayakumarrt Shell Programming and Scripting 2 05-09-2008 04:48 AM
ksh - read file with leading spaces momi Shell Programming and Scripting 2 03-17-2008 03:02 PM
read string, check string length and cut ozzy80 Shell Programming and Scripting 9 03-21-2007 05:56 PM
sed problem - replacement string should be same length as matching string. amangeles Shell Programming and Scripting 4 01-11-2006 06:11 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-13-2008
dayamatrix dayamatrix is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Post Read a string with leading spaces and find the length of the string

HI

In my script, i am reading the input from the user and want to find the length of the string.

The input may contain leading spaces. Right now, when leading spaces are there, they are not counted.

Kindly help me

My script is like below. I am using the ksh.

#!/usr/bin/ksh

echo "enter your value"
read "A"
len=echo ${#A}
echo "length of the string you entered is $len"


output:
enter your value
asdf
length of the string you entered is 4

NOte: I have entered 8 char (4 spaces + 4 char)


Kindly help me
  #2 (permalink)  
Old 11-13-2008
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 610
Set the IFS before "read":

IFS=""
  #3 (permalink)  
Old 11-13-2008
dayamatrix dayamatrix is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 4
Post Thank you very much

HI
Thank you very much for the timely reply
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:47 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0