Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Software
User Name
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.


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

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

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)
read cmd

how to read arrow key press??
Old 08-01-2007, 06:36 AM   #2
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
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
LQ Newbie
Registered: Apr 2004
Posts: 15

Rep: Reputation: 0

maybe compile this with gcc -o FILENAME

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

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

int getch();

int main()
        char chr;
        chr =getch();

int getch( ) {
        struct termios oldt,
        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;


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 > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:29 AM.

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