The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to append spaces(say 10 spaces) at the end of each line based on the length of th prathima UNIX for Dummies Questions & Answers 2 04-29-2008 02:43 PM
ksh - read file with leading spaces momi Shell Programming and Scripting 2 03-17-2008 12:02 PM
adding spaces to a line mgirinath Shell Programming and Scripting 4 03-23-2007 09:38 AM
Read files including spaces kumariak Shell Programming and Scripting 4 06-08-2005 04:36 AM
Keep spaces with read command azmathshaikh Shell Programming and Scripting 3 03-22-2005 01:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 07-03-2006
Registered User
 

Join Date: Jul 2006
Posts: 2
How to read a line when it starts with spaces

Hi ,
I use read command to get the input text, When i try to get the line starting with spaces or ending with spaces it automatically truncates the spaces and displays the remaining content.

Code i tried (UserInput.sh):

#!/bin/bash
echo -n "Enter some text > "
read text
echo "You entered: $text"

When i give this as input " Hello How "

It displays "You entered: Hello How" , It has truncated the spaces. Is there any way to get Input along with spaces ?

Thank U,
Prakash C.
Reply With Quote
Forum Sponsor
  #2  
Old 07-03-2006
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,297
Code:
#!/bin/ksh
print "Enter something"
IFS=
read var
IFS=" "
print "$var"
Reply With Quote
  #3  
Old 07-03-2006
Hitori's Avatar
Registered User
 

Join Date: Jun 2006
Posts: 360
bash

look at Bash Reference Manual: Word Splitting

This approach (i.e.
IFS=
) will work in bash too
Reply With Quote
  #4  
Old 07-03-2006
Registered User
 

Join Date: Jul 2006
Posts: 2
Thank u for replying

It has worked for me.

Thanks,
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 11:07 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0