This repository contains the implementation of an interactive POSIX-compatible shell. The project showcases process management, input parsing, and system-level functionality with various built-in commands and features.
- Command Execution: Executes both built-in and external commands.
- Piping and Redirection: Supports pipes (
|) and I/O redirection (<,>). - Job Control: Handles foreground and background processes (
&). - History Management: Maintains a command history (up to 20 commands) across sessions.
- Signal Handling: Processes interrupts like
Ctrl+C,Ctrl+Z, andCtrl+D.
headers.h: Contains all include files, function definitions, and extern variables.main.cpp: Driver code that decides which methods to call.prompt.cpp: Displays the shell prompt.parse_input.cpp: Parses and tokenizes the user input.cmd_handler.cpp: Decides which command to call based on parsed input.background.cpp: Forks and runs processes in the background.cd.cpp: Implements thecdcommand for changing directories.ls.cpp: Implements thelscommand to list directory contents.pinfo.cpp: Displays process information.pipe.cpp: Manages and executes commands with pipes.pwd.cpp: Implements thepwdcommand to display the current working directory.redirection.cpp: Handles input and output redirection.search.cpp: Recursively searches for a file in the current directory.sig_handler.cpp: Manages signals likeCtrl+Z,Ctrl+C, andCtrl+D.makefile: Configuration file to compile all.cppfiles.history.cpp: Implements thehistorycommand, storing up to 20 commands across sessions in a file.
Run the following commands in a terminal (Linux) to compile and execute the shell:
make
./a.out- Pipes (
|) and I/O redirection operators (<,>) are preceded and succeeded by spaces. - The user runs the executable (
a.out) from the directory where it is located.
> ls -la
> echo "Welcome to the interactive shell"> sleep 10 &> cat file.txt | grep "keyword"
> ls > output.txt> history> search myfile.txt.
├── src/ # Source code files
├── include/ # Header files
├── makefile # Build system configuration
└── README.md # Documentation
Contributions are welcome! Feel free to open an issue or submit a pull request.