LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-26-2006, 04:04 PM   #1
ChrisScott
Member
 
Registered: Nov 2006
Location: St Albans, England
Distribution: Fedora c3/5, Suse pro 10/openSuse 10.2, RHES, Zenwalk.....
Posts: 97

Rep: Reputation: 15
Trying to write a BASH script which allows input of paragraphs


Hi all.

I've written a BASH script which generates a Latex document. Most of the info is generated by the program however I need to include a user input which is not ended by hitting return.

At the moment I'm just using the 'read' command, but obviously to seperate paragraphs the user has to press enter - which finishes the input.

Is there another way to take inputs or can you get read to ignore the enter key - if so how can the user tell the program that the input is finished?

I'm a bit confused any help or ideas would be apreciated.

Thanks Chris

Last edited by ChrisScott; 11-26-2006 at 04:08 PM.
 
Old 11-26-2006, 04:26 PM   #2
ChrisScott
Member
 
Registered: Nov 2006
Location: St Albans, England
Distribution: Fedora c3/5, Suse pro 10/openSuse 10.2, RHES, Zenwalk.....
Posts: 97

Original Poster
Rep: Reputation: 15
Idea

I've had an idea, I used a loop as so:

while [ input != "end" ] ; do

read input
echo "$input" >> inputf

done

cat inputf

However, when I ran this 'end' didn't finish the input and I was stuck in an infinite loop!
 
Old 11-26-2006, 04:31 PM   #3
cs-cam
Senior Member
 
Registered: May 2004
Location: Australia
Distribution: Gentoo
Posts: 3,545

Rep: Reputation: 57
Hmm, there is probably a trick somewhere and I'm going about it the long way but a temporary solution would be to use cat.
Code:
cat > /tmp/tmpfile.txt
PARAGRAPH=$(cat /tmp/tmpfile.txt)
 
Old 11-26-2006, 04:46 PM   #4
ChrisScott
Member
 
Registered: Nov 2006
Location: St Albans, England
Distribution: Fedora c3/5, Suse pro 10/openSuse 10.2, RHES, Zenwalk.....
Posts: 97

Original Poster
Rep: Reputation: 15
Cheers!

Yeah I think that will be perfectly suitable, it's not that long. Thanks. If you come across the trick let me know.
 
Old 11-26-2006, 05:11 PM   #5
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
I think this will demonstrate what you want. The cat line is the important one - the others are just fluff for the demo.
Code:
#!/bin/bash
tmp=$(mktemp)
echo "OK, enter some text.  Control-D to end"
cat > $tmp
echo ""
echo "OK, here's what you entered"
cat $tmp
rm -f $tmp
 
Old 11-26-2006, 05:25 PM   #6
ChrisScott
Member
 
Registered: Nov 2006
Location: St Albans, England
Distribution: Fedora c3/5, Suse pro 10/openSuse 10.2, RHES, Zenwalk.....
Posts: 97

Original Poster
Rep: Reputation: 15
actually....

sorry, but that didn't quite work:

It did on the command prompt but after I replied to your last post I put the command into my shell script which completely ignored it - no error - no prompt - nothing. Don't know if I did something stupid? I used,

cat > /tmp/example.txt



I posted this just after matthew - so haven't read his yet! maybe you can ignore this one!

Last edited by ChrisScott; 11-26-2006 at 05:29 PM.
 
Old 11-26-2006, 05:32 PM   #7
ChrisScott
Member
 
Registered: Nov 2006
Location: St Albans, England
Distribution: Fedora c3/5, Suse pro 10/openSuse 10.2, RHES, Zenwalk.....
Posts: 97

Original Poster
Rep: Reputation: 15
Yeah thanks Matthew that works great.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script pipe input - bash mostly laikos Programming 4 11-09-2008 05:14 PM
mask user input in a bash script PlatinumRik Linux - Software 1 06-15-2004 10:06 AM
send automatic input to a script called by another script in bash programming jorgecab Programming 2 04-01-2004 12:20 AM
User input using a BASH script... causticmtl Programming 5 07-13-2003 09:59 PM
bash-script input aizkorri Programming 7 07-08-2003 06:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration