-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
40 lines (32 loc) · 1.06 KB
/
shell.c
File metadata and controls
40 lines (32 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <readline/readline.h>
#include <readline/history.h>
int main() {
char *input;
char *prompt = "myshell> ";
// Initialisiere die Readline-Bibliothek für die Befehlshistorie
using_history();
while ((input = readline(prompt)) != NULL) {
// Füge den eingegebenen Befehl zur Befehlshistorie hinzu
add_history(input);
// Überprüfe, ob der Befehl "history" ist
if (strcmp(input, "history") == 0) {
HIST_ENTRY **hist_list = history_list();
if (hist_list) {
for (int i = 0; hist_list[i]; i++) {
printf("%d: %s\n", i + history_base, hist_list[i]->line);
}
}
}
// Gib die eingegebene Zeile und eine neue Zeile für die Benutzereingabe aus
rl_on_new_line();
rl_replace_line("", 0);
rl_redisplay();
free(input);
}
// Beende die Verwendung der Readline-Bibliothek für die Befehlshistorie
//free_history();
return 0;
}