The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan UNIX for Dummies Questions & Answers 3 08-02-2008 05:21 PM
How to write to stdin of another program (program A -> [stdin]program B) vvaidyan High Level Programming 1 04-30-2008 01:44 PM
Need help with shellscript jigarlakhani Shell Programming and Scripting 2 11-22-2007 08:28 AM
HOWTO: Calculate the balance of work in multi-threaded app. DreamWarrior High Level Programming 2 11-01-2006 10:54 AM
ftp in Shellscript ggowrish UNIX for Advanced & Expert Users 3 06-11-2004 08:09 AM

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

Join Date: Sep 2008
Location: OS X 10.5.5 /bin/bash 3.2.17
Posts: 26
Howto get readline to work in shellscript (stdin)

GNU readline works fine on my system.

But my shell script takes stdin from user such as :

cat >> filename.

I want to be able to use editing commands on the stdin. Currently, I am unable to even reedit the existing line (go back over what has been typed other than backspace which deletes).

How can i get readline to work on stdin. If it is not possible with "cat" is there some other command i can use ?

Thanks.
  #2 (permalink)  
Old 09-15-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
If you are using bash, read -e appears to use GNU readline.
  #3 (permalink)  
Old 09-15-2008
sentinel sentinel is offline
Registered User
  
 

Join Date: Sep 2008
Location: OS X 10.5.5 /bin/bash 3.2.17
Posts: 26
Thanks, yes that does work. However, it works for one line. With cat I would need to use multiple lines. Let me see if I can find someway to do that. A loop perhaps -- while read -e line -- let me try it out and get back.

I did find something called "rlwrap" that works well. I do "rlwrap cat >> filename". You can wrap any command with rlwrap.

After trying rlwrap in my shellscript, my requirements increased! Now I would like to go up and edit the previous line, too. (Why can't I just invoke vi and stop being geeky!).
(iirc, zsh allows that).
  #4 (permalink)  
Old 09-15-2008
Annihilannic Annihilannic is offline Forum Advisor  
  
 

Join Date: May 2008
Location: Sydney, Australia
Posts: 1,009
Never let it be said that "it can't be done", but I think it'd be difficult to find something that would do that. The reason being that vi uses the terminal in "curses" mode, where the positions of every character visible on the terminal are managed explicitly by the application.

When the terminal is not in this mode it operates in a line by line "stream" fashion, where the shell throws characters at the terminal in a reasonably organised order, but does not track what happens to them after that, so is incapable of going back to previous lines to edit them.

I think anything you do to try and combine the two will result in something with limited portability and plenty of potential for unexpected behaviour.
Closed Thread

Bookmarks

Tags
shell script. gnu readline

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 11:37 PM.


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