Stop being the product.
Become the owner.
or
sign uplog in

How to create an interactive shell mode Hey there! I'm…

How to create an interactive shell mode

Hey there! I'm experimenting with POSIX api and I want to create my own mini shell. I want my shell to open an interactive shell mode and be able to receive command input line by line from the kernel. I am not sure how to achieve this. If I am not mistaken, I read that I should be able to somehow link my shell to a /dev/ttyX or /dev/pts/X driver in "cooked mode" (my shell only receives input only after a user presses 'ENTER', not after every keypress)

Ive tried Googling for the solution, but its been ineffective. Im so confused, I don't even know how to look for a solution for this.


Here is the current code snippet of my program. (Excuse the bad programming) `initInteractiveMode` is meant to initialize interactive mode

```
#include <stdio.h>
#include <string.h>
#include <termios.h>

#define VERSION "0.0.1"

int parseArguments(int argc, char *argv[]);
void help();
void initInteractiveMode();

int main(int argc, char *argv[]) {
if (argc < 2) {
printf("shell\n");
return 0;
}

if (!parseArguments(argc, argv)) {
return 0;
}

initInteractiveMode(); // Initialize Interactive Mode

printf("Chloe's shell interactive mode enabled\n\n");

while (1) {
}

return 0;
}

// TODO: Open interactive mode
void initInteractiveMode() {

}

int parseArguments(int argc, char *argv[]) {
const char *arg = argv[1];
if (strcmp(arg, "-v") == 0 || strcmp(arg, "--version") == 0) {
printf("Chloe's shell, version %s\n", VERSION);
} else if (strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) {
help();
} else if (strcmp(arg, "interactive") == 0 || strcmp(arg, "i") == 0) {
return 1; // Enter interactive mode
} else {
printf("Invalid command\n\n");
help();
}

return 0;
}

void help() {
printf("Chloe's shell\n\n");
printf("\033[1mCommand:\033[0m shell [options]\n\n");
printf("List of options:\n");
printf("A simple shell for testing POSIX system calls\n");
printf("interactive\tEnter interactive mode\n");
printf("--help | -h\tDisplay help information\n");
printf("--version | -v\tDisplay version information\n");
}
```
#dev #programming #technology
source
earnings
4,000 mlx total
$0  total
engagement
7 views
0 reactions

0 comments