This project implements a basic Unix-like shell in C as an educational exercise. It demonstrates core concepts of process management, input/output handling, and command execution in a POSIX environment. The shell is not intended for production use and serves solely as a learning tool to explore shell internals.
The shell supports a range of fundamental shell behaviors, including:
- External command launching via
forkandexec. - Resolve enviornment variables.
- Directory navigation using
cd, including~expansion for home directories.
- Sequential execution of semicolon-separated (
;) commands. - Conditional chaining with
&&and||based on exit statuses. - Subshells enclosed in parentheses for isolated execution.
- Exit code negation using
!. - Line continuation with backslashes and support for multiline command lists.
- Shell process replacement via
exec(applied twice for added reliability).
- Pipeline operations using
|. - Input/output redirection with
[n]<,[n]>,[n]<>, and[n]>>. - Permission validation for redirection targets.
- SIGINT (Ctrl+C) handling to interrupt foreground processes and return to the shell prompt.
- At the input prompt, Ctrl+C refreshes the prompt and restarts the input loop, mimicking bash behavior without terminating the shell.
- GCC or compatible C compiler.
- POSIX-compliant system (e.g., Linux, macOS).
makeThis builds the executable cshell in the current directory.
Launch the shell:
./cshellExit with exit or Ctrl+D.
- Error handling focuses on usability, printing diagnostics to stderr.
- The implementation prioritizes clarity over optimization.
- Stephen Brennan's Write a Shell in C
- Indradhanush Gupta's Writing a UNIX shell
- Tokenrove's Build-your-own-shell
This project is for personal learning and is not licensed for redistribution or commercial use.