An Interest In:
Web News this Week
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
Writing my own minimal shell in C - Part 1 (The constraints)
Day 1 - Understanding the Problem.
This is my attempt to replicate the behavior of BASH or (Bourne again shell) command line interpreter for a school project. Before we get into how to get into the solution and the general approach of making the shell. Let's first look at all the constraints and what is expected from this minimal shell.
First and foremost, standard library functions I am allowed to use.
Below is the list of the external functions / standard library functions that I am allowed to use, if I need any another function I must code it myself. Please see the man pages of these functions if you do not recognize them.
readline, rl_clear_history, rl_on_new_line, rl_replace_line, rl_redisplay, add_history, printf, malloc, free, write, access, open, read, close, fork, wait, waitpid, wait3, wait4, signal, sigaction, kill, exit, getcwd, chdir, stat, lstat, fstat, unlink, execve, dup, dup2, pipe, opendir, readdir, closedir, strerror, perror, isatty, ttyname, ttyslot, ioctl, getenv, tcsetattr, tcgetattr, tgetflag, tgetnum, tgetstr, tgoto, tputs
Expectations from the shell, what must this minimal shell do
It must implement the builtin shell functions
- echo with the option -n
- cd with only a relative or absolute path
- pwd with no options
- export with no options
- unset with no options
- env with no options or arguments
- exit with no options
Redirections
- < should redirect input
- > should redirect output
- << read input from the current source until a line containing only the delimiter is even.
- >> should redirect output in append mode.
Pipes
- | The output of each command in the pipeline is connected via a pipe to the input of the next command
Environment Variables ($ followed by characters ) should expand to their values.
$? should expand to the exit status of the most recently executed foreground pipeline
For some simplification, the shell must not interpret unclosed quotes or unspecified special characters like '\' or ';' etc
The shell must show a prompt waiting for next command, have a working history and must only use one global variable.
ctrl-C ctrl-D ctrl-\ should work like bash. When interactive:
- ctrl-C print a new prompt on a newline
- ctrl-D exit the shell.
Lets begin researching the problems and the areas of Operating System I am less familiar with, in the next part of this series I will break down the general overview of the design and I will try to make it super modular.
Original Link: https://dev.to/harshbanthiya/writing-my-own-minimal-shell-in-c-part-1-the-constraints-20cg
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To