LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 07-31-2007, 06:11 AM   #1
sudevank
LQ Newbie
 
Registered: Mar 2007
Posts: 27

Rep: Reputation: 15
how to implement history in myown script


Hi,
I done a script which will accept user commands. i am using read in a while loop. an do actions.

But now i need the history also. how to implement that? when use pres up arrow the previous command should display.

my current code sample

while (1)
do
read cmd
act($cmd)
done

how to read arrow key press??
thanks
 
Old 08-01-2007, 06:36 AM   #2
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 30
I am unaware of anything in bash which will read a single arbitrary keystroke.

You'll need to write some sort of helper application to do that. Do you know C?
 
Old 08-01-2007, 07:05 AM   #3
sudevank
LQ Newbie
 
Registered: Mar 2007
Posts: 27

Original Poster
Rep: Reputation: 15
I know C ut i am not interested to do big task. If someone press backspace or delete how we will update the display in same lne?
the 'read -n1 var' will read one character.
the arrow keys consists of three characters so read -n3 is good.
but it fails to read backspace etc.
 
Old 08-01-2007, 08:57 AM   #4
The_Spider
LQ Newbie
 
Registered: Apr 2004
Posts: 15

Rep: Reputation: 0
Hi,

maybe compile this with gcc -o FILENAME

it should spit any input char directly to output, maybe you can use this?

Code:
#include <stdio.h>
#include <termios.h>
#include <unistd.h>


int getch();

int main()
{
        char chr;
        chr =getch();
        fputc(chr,stdout);
}


int getch( ) {
        struct termios oldt,
                                   newt;
        int ch;
        tcgetattr( STDIN_FILENO, &oldt );
        newt = oldt;
        newt.c_lflag &= ~( ICANON | ECHO );
        tcsetattr( STDIN_FILENO, TCSANOW, &newt );
        ch = getchar();
        tcsetattr( STDIN_FILENO, TCSANOW, &oldt );
        return ch;
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
best way to implement syslog slug420 Linux - General 2 03-21-2007 01:23 PM
history command from script sharonenoch Programming 5 03-17-2006 07:48 AM
Download history and copy history? inverted.gravity Linux - Newbie 1 02-21-2006 12:31 PM
how to implement an endless loop in a rc startup script garba Linux - General 6 05-03-2005 11:30 AM
How to find back "history" database after "history -c" ? san_lss Linux - Newbie 1 01-07-2004 11:53 AM


All times are GMT -5. The time now is 07:09 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration