- A shell is a command line interface(CLI) that allows users to interact with an Operating System(OS) by entering commands. It takes user input, interprets it, and executes the corresponding system calls to perform tasks like running programs, managing files, etc.
-
Execute commands from the user.
-
Support for both interactive and non-interactive modes.
-
Handle built-in commands like
cd,env, andexit. -
Process management using
fork(),execvp(), andwaitpid(). -
Tokenization and command parsing.
Building a shell is a valuable learning experience. To gain a deeper understanding of the inner workings of how the shell operates including process management, I/O handling, and interaction with the kernel (Core part of the OS).
To compile the shell, use Makefile:
makeThis will generate the executable file inside the build/ directory.
Interactive mode: ./build/hsh
Non-interactive mode: echo "/bin/ls" | ./build/hsh
- Run shell in interactive mode:
$ ./build/hsh
#cisfun$ ls -l $ ./build/hsh
#cisfun$ pwd
/home/{username}/{dir}/simple_shell $ ./build/hsh
#cisfun$ echo “Hello, World!”
“Hello, World!”- Run shell in non-interactive mode:
$ echo "/bin/ls" | ./build/hsh
exec.c interactive.c hsh read_line.c non_interactive.c shell.c read_stream.c tokenize.c
process.c shell.h $ echo "pwd" | ./build/hsh
/home/{username}/{dir}/simple_shell-
man 3 execvp -
man 2 fork -
man 2 waitpid -
man 3 getenv
This project was jointly created by @SherneVK and @droffilc1