How to read a line when it starts with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read a line when it starts with spaces
# 1  
Old 07-03-2006
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.
# 2  
Old 07-03-2006
Code:
#!/bin/ksh
print "Enter something"
IFS=
read var
IFS=" "
print "$var"

# 3  
Old 07-03-2006
bash

look at Bash Reference Manual: Word Splitting

This approach (i.e.
IFS=
) will work in bash too
# 4  
Old 07-03-2006
Thank u for replying

It has worked for me. Smilie

Thanks,
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to write a shell script that starts one, then kills it, then starts another?

This is on a CentOS box, I have two scripts that need to run in order. I want to write a shell script that calls the first script, lets it run and then terminates it after a certain number of hours (that I specify of course), and then calls the second script (they can't run simultaneously) which... (3 Replies)
Discussion started by: btramer
3 Replies

2. Homework & Coursework Questions

When I run the script, the cursor starts on the wrong line?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: It's a shell script using a looping logic, trap, tput, if, while. Most of the scripts in this book aren't written... (2 Replies)
Discussion started by: ckleinholz
2 Replies

3. Shell Programming and Scripting

Moving line up if line starts with + sign.

Hello everyone, I'm struggling with this command: awk '!/^\+/{ORS=FS}/^\+/{ORS=RS}1' file1 > file2 What I want to do is to move any line that starts with the + sign 1 up, so its the continuation of the previous. The above command is messing the whole output, can you please let me know... (8 Replies)
Discussion started by: demmel
8 Replies

4. Shell Programming and Scripting

Merge multiple lines to one line when line starts with and ends with

example: comment Now_TB.table column errac is for error messages 1 - first 2 - second 3 -third ; in this example I need to be able to grab the comment as first word and ; as the last word and it might span a few lines. I need it to be put all in one line without line breaks so I can... (4 Replies)
Discussion started by: wambli
4 Replies

5. UNIX for Dummies Questions & Answers

How to read files with spaces

Hi I am a newbie to unix. I have a current script that reads a directory for excel files and renames the files. There is a problem now because some of the files have spaces. If I put quotes on the file, it will work but I dont know how to read all the files with quotes. Variables $1 =... (6 Replies)
Discussion started by: Lillyt
6 Replies

6. Shell Programming and Scripting

bash: read file line by line (lines have '\0') - not full line has read???

I am using the while-loop to read a file. The file has lines with null-terminated strings (words, actually.) What I have by that reading - just a first word up to '\0'! I need to have whole string up to 'new line' - (LF, 10#10, 16#A) What I am doing wrong? #make file 'grb' with... (6 Replies)
Discussion started by: alex_5161
6 Replies

7. Shell Programming and Scripting

Read file line spaces

I have a script which read a file it does while read -r line, then i echo line out echo "$line" Problem is the echo does not echo space and tabs at the end of each line. How do i get the end of line space as well (6 Replies)
Discussion started by: kelseyh
6 Replies

8. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

9. Shell Programming and Scripting

script to read a line with spaces bet " " and write to a file

Hi, I need a command in UNIX KSH below is the description... MAPPING DESCRIPTION ="Test Mapping for the calid inputs" ISVALID ="YES" NAME ="m_test_xml" OBJECTVERSION ="1" VERSIONNUMBER ="1" unix ksh command to read the DESCRIPTION and write to a file Test Mapping for the calid inputs... (3 Replies)
Discussion started by: perlamohan
3 Replies

10. Shell Programming and Scripting

Keep spaces with read command

Hi The following command read a string from the keyboard & echo it back. $ read S;echo "$S" ABCD ABCD As you see, the input has space. while it echo back the spaces are removed. Is there a way to keep the input intact and not removing any spaces? Also, the number of spaces may vary. ... (3 Replies)
Discussion started by: azmathshaikh
3 Replies
Login or Register to Ask a Question