LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-12-2008, 11:06 PM   #1
sagsriv
LQ Newbie
 
Registered: Jan 2008
Location: Kolkata India
Distribution: fedora 6
Posts: 21

Rep: Reputation: 15
how command is repeated in terminals in bash shell


I am on the process of making a shell . It has some functionalities and a little bit of signal handling. Now I want to know how in bash shell commands are repeated using an arrow key(u can see the previous command when u press the up arrow).Can anyone give me some idea?
 
Old 03-12-2008, 11:23 PM   #2
sagsriv
LQ Newbie
 
Registered: Jan 2008
Location: Kolkata India
Distribution: fedora 6
Posts: 21

Original Poster
Rep: Reputation: 15
Well I thought my post needed a revision. Consider the following code fragment:

#include <stdio.h>
#include <stdlib.h>

int main(){
char c = getchar();
printf("%c\t%d\n",c,c);
return 0;
}

Whenever I run this program the character I press a key to get a character. that character is echoed on terminal.Then again the char and its ascii value is printed.All I want is that the character is not echoed on the screen when I press it.For example with char 'a' I get printed:
a
a 97
but I want 'a 97' only.Is there a way of doing that?
Another thing,consider the same program with input of 'up arrow key'(not the string,for sure).It prints on terminal :
^[[A
> 27
=
'>
='(character is not entirely like that,but copying from terminal doesnot put the correct character)
Does some keys in the keyboard are handled some other way?

Last edited by sagsriv; 03-12-2008 at 11:27 PM.
 
Old 03-13-2008, 01:05 AM   #3
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
This fits better in the programming section.

You have to switch your terminal to raw mode; see man termios (function cfmakeraw()).

Further, when you press some keys (like arrows, home etc), multiple characters are placed in the input buffer.
 
Old 03-13-2008, 02:41 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
hello Wim Sturkenboom. I've been thinking this for a while but does this mean that bash always receive encoded characters and no more raw input? I mean no more scan codes or the likes?
 
Old 03-17-2008, 03:53 AM   #5
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
I think it does although I'm not sure.
 
  


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
Shell Bash Command Expot Maurice Arthur Mandriva 5 01-24-2008 08:22 PM
while writing your own Bash shell command basak Linux - Software 4 08-02-2006 10:58 AM
about the bash shell command naihe2010 Programming 7 10-27-2005 12:40 AM
Bash script - repeated command satimis Programming 27 10-28-2004 05:02 AM
Bash shell command on windows98 emailssent General 3 10-16-2004 06:25 AM


All times are GMT -5. The time now is 02:00 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration