Unix-like shell implemented in C. It provides a command-line interface for executing internal and external commands, managing foreground and background processes, handling signals, and maintaining a command history.
-
External Commands:
- Supports execution of external programs using
fork()andexecvp. - Background process execution with
&.
- Supports execution of external programs using
-
Command History:
- Tracks the last 10 commands entered.
- Displays commands in reverse order (most recent first).
-
Signal Handling:
- Handles
SIGINT(Ctrl+C) appropriately without crashing the shell.
- Handles
-
Process Management:
- Supports foreground and background processes.
- Cleans up zombie processes to prevent resource leaks.
-
Built-in Commands:
help: Display help information for internal commands.pwd: Print the current working directory.cd: Change the current directory, with support for:cd(no arguments): Navigate to the home directory.cd -: Return to the previous directory.cd ~/dir: Expand~to the home directory.
history: View and re-run commands from the history.!!: Re-run the last command.!n: Re-run the nth command in history.
exit: Exit the shell.
To build and run this project, you need:
- A Unix-like environment (Linux, macOS, or WSL on Windows).
gccorclang(for compiling the code).CMake(for building the project).
- Install WSL:
- Open PowerShell as Administrator and run:
wsl --install - Restart your computer if prompted.
- Open PowerShell as Administrator and run:
- Install a Linux distribution (e.g., Ubuntu) from the Microsoft Store.
- Open the WSL terminal and install the required tools:
sudo apt update sudo apt install build-essential cmake
- Clone the project and navigate to the project root:
git clone <repo-url> cd Unix-Shell
- Create and navigate to the build directory:
mkdir build cd build - Create the executable:
cmake .. make
- Run the shell executable:
./shell
-
System-Level Programming:
- Uses system calls like
fork,execvp, andwaitpidto manage processes. - Implements signal handling with
sigactionto gracefully handle interrupts (e.g.,Ctrl+C).
- Uses system calls like
-
Command Parsing:
- Tokenizes user input to parse commands, arguments, and background execution (
&).
- Tokenizes user input to parse commands, arguments, and background execution (
-
Dynamic Memory Management:
- Dynamically allocates and manages memory for command history and input parsing.
-
Portability:
- Designed for POSIX-compliant Unix-like systems (Linux, macOS, WSL).
-
No Advanced Shell Features:
- Does not support piping (
|) or input/output redirection (>,<).
- Does not support piping (
-
Limited History:
- Command history is limited to the last 10 commands and is not persistent across sessions.
-
No Job Control:
- Does not implement job control commands such as
fg,bg, orjobs.
- Does not implement job control commands such as
-
Platform Constraints:
- Intended for Unix-like environments, not designed to run natively on Windows without WSL.