diff options
author | scratko <m@scratko.xyz> | 2025-07-28 03:55:01 +0300 |
---|---|---|
committer | scratko <m@scratko.xyz> | 2025-08-03 03:12:43 +0300 |
commit | dd9ed7190681050676797555e2212884687a8f11 (patch) | |
tree | 287efea01234e1297d964714a6d8bece0f44a6e4 /README.md | |
parent | 0de355ebbf6d9eb9ab673da22eb18cbb01d005f8 (diff) | |
download | shell-dd9ed7190681050676797555e2212884687a8f11.tar.gz shell-dd9ed7190681050676797555e2212884687a8f11.tar.bz2 shell-dd9ed7190681050676797555e2212884687a8f11.zip |
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..7f30423 --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +# Simple UNIX Shell + +A lightweight command-line shell implemented in C, designed to emulate core +functionalities of UNIX shells like `sh` or `bash`. This shell supports +**process management**, **I/O redirection**, **pipelining (|)**, **subshells**, +**logical operators (&&, ||)**, **interactive input handling including +autocompletion** and **basic signal handling**. The implementation demonstrates +system-level programming concepts using **POSIX APIs**. + +<img src="shell_1.png" /> + +<img src="shell_2.png" /> + +--- + +## Features + +- **Command Execution** +Executes external programs using `fork()` and `execvp()`, with environment lookup +via `$PATH`. + +- **Foreground and background job execution** +Commands can be run in the background by appending `&`. + +- **Redirection** +Input/output redirection using `<`, `>`, and `>>`. _Examples:_ + - `cat < input.txt` + - `ls > out.txt` + - `echo foo >> log.txt` + +- **Quoting and escape sequences** +Basic support for `"quoted strings"` and escape sequences like `\ ` or `\"`. + +- **Logical Operators** +Implements support for `&&` and `||` operators, enabling conditional command +execution. These operators can be combined with pipelines and subshells. + +- **Subshells** +Commands enclosed in parentheses `()` are executed in subshells, +enabling complex nested logic. + +- **Pipelines** +Unix-style pipelines using the pipe (|) operator. Data is passed from one +process to another via standard input/output. +_Example: `cat file.txt | grep foo | sort`_ + +- **Directory Navigation** +Supports the built-in `cd` command to change the current working directory via +`chdir()`. + +- **Autocompletion (Tab)** +Custom autocompletion implemented using raw terminal input: + - If the current token is a command: matches against executables in `$PATH`. + - Otherwise: matches file and directory names from the current or specified path. + +- **Interactive Line Editing** +Terminal is switched to non-canonical mode. Input handling is implemented manually: + - Character-by-character input display. + - Left/right arrow keys for cursor movement. + - `Backspace` support with live line re-rendering. + - `Ctrl+D` to terminate the shell. + - `Tab` triggers autocompletion. + +- **Signal handling** +Handles SIGCHLD to reap zombie processes and prevent defunct children. + +--- + +## Technologies Used + +- **Language**: C (C99) +- **System APIs**: POSIX (`fork`, `execvp`, `waitpid`, `pipe`, `dup2`, `tcsetpgrp`, etc.) +- **Memory handling**: dynamic memory allocation (`malloc`, `free`) +- **Terminal control**: `tcgetpgrp`, `tcsetpgrp`, `tcgetattr`, `tcsetattr` + +--- + +## Limitations + +While the shell supports many core UNIX behaviors, it has some limitations compared to full-featured shells: + +- No scripting constructs (`if`, `while`, `for`, etc.) +- No variable expansion (e.g. `$HOME`, `$PATH`, `$?`) +- No command substitution (e.g. `` `command` `` or `$(command)`) +- No history (up arrow) +- No job control (e.g. fg, bg, jobs). +- No advanced signal features (sigaction, sigprocmask, kill, etc.). + +You’ll see a prompt where you can enter commands, use pipes, redirection, and +job control. You can also interact via signals like Ctrl+C and Ctrl+Z. |