Re: bash trick - prefixing a command?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2005-10-25 at 18:32 +0000, rrmalloy@xxxxxxxxxxx wrote:
> Have you looked at the GNU readline library?
> It may give you enough command line editing and history features
> for you purpose.

Readline stuff seems nice. As a test, just for make this lib work, you
can base your code on (based on the links and suggestions of this same
thread):

[rodolfoap] /home/rodolfoap/dat/devel > cat rl.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <readline/readline.h>
#include <readline/history.h>
#define PROMPT "$ "

void handle_signal(int signo) {
        printf("\n%s", PROMPT);
        fflush(stdout);
}
int main(int argc, char **argv, char **envp){
        signal(SIGINT, SIG_IGN);
        signal(SIGINT, handle_signal);
        char *temp = NULL;
        while ((temp=readline(PROMPT)) != NULL) {
                if (*temp) {
                        system(temp);
                        add_history (temp);
                }
                if (strcmp (temp, "exit") == 0){
                        free(temp);
                        break;
                }
                free (temp);
        }
        return 0;
}
[rodolfoap] /home/rodolfoap/dat/devel > gcc rl.c -lcurses -lreadline
-lhistory -o rl
[rodolfoap] /home/rodolfoap/dat/devel > ./rl
$ mc (NOTE: IT WORKS!, gets the screen fine!)

$ pwd
/home/rodolfoap/dat/devel
$ ls /
bin  boot  data  dev  etc  home  lib  local  lost+found  media  misc
mnt  net  opt  proc  root  rpm  sbin  selinux  srv  sys  tmp  usr  var
$ ls -l /
total 164
drwxr-xr-x    2 root      root       4096 Oct 27 08:18 bin
drwxr-xr-x    3 root      root       4096 Oct 21 08:06 boot
drwxr-xr-x    8 rodolfoap rodolfoap  4096 Oct 21 23:00 data
drwxr-xr-x    9 root      root       4300 Oct 27 07:04 dev
drwxr-xr-x  100 root      root      12288 Oct 27 08:18 etc
drwxr-xr-x    3 root      root       4096 Sep 30 17:42 home
drwxr-xr-x   11 root      root       4096 Oct 27 08:17 lib
drwxr-xr-x    5 rodolfoap rodolfoap  4096 Oct 10 10:35 local
drwx------    2 root      root      16384 Jul 11 13:30 lost+found
drwxr-xr-x    5 root      root       4096 Oct 27 07:04 media
drwxr-xr-x    2 root      root          0 Oct 27 07:03 misc
drwxr-xr-x    2 root      root       4096 May 23 00:28 mnt
drwxr-xr-x    2 root      root          0 Oct 27 07:03 net
drwxr-xr-x    3 root      root       4096 Jul 20 07:25 opt
dr-xr-xr-x  153 root      root          0 Oct 27 03:03 proc
drwxr-x---   55 root      root       4096 Oct 27 08:46 root
drwxr-xr-x    5 rodolfoap rodolfoap  4096 Sep 30 16:48 rpm
drwxr-xr-x    2 root      root      12288 Oct 18 07:10 sbin
drwxr-xr-x    2 root      root       4096 Jul 11 17:31 selinux
drwxr-xr-x    2 root      root       4096 May 23 00:28 srv
drwxr-xr-x   10 root      root          0 Oct 27 03:03 sys
drwxrwxrwt   21 root      root       4096 Oct 27 12:32 tmp
drwxr-xr-x   17 root      root       4096 Aug 17 08:09 usr
drwxr-xr-x   27 root      root       4096 Oct 25 07:09 var
$

Good luck!
--
Rodolfo Alcazar - rodolfo.alcazar@xxxxxxxxxxxx
Netzmanager Padep, GTZ
591-70656800, -22417628, LA PAZ, BOLIVIA
http://otbits.blogspot.com
--
New systems generate new problems.




[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux