Skip to content

weemsj/small_shell

Repository files navigation

smallsh

📖 Overview

smallsh is a simple Unix-like shell written in C. It provides a subset of features found in popular shells like bash, including process management, I/O redirection, and custom signal handling.

This project was designed as a hands-on exercise in systems programming, focusing on process control, signals, and command execution using low-level system calls.

📝 Note: This shell was created and tested on a remote Linux server using the Kitty terminal. Some functionalities (especially signal handling or background processes) may not behave exactly the same in other environments or terminal emulators.


✨ Features

  • Command Prompt -- Interactive prompt for entering commands\
  • Comments & Blank Lines -- Handles blank lines and ignores # comments\
  • Variable Expansion -- Supports $$ expansion, replaced with the shell's process ID

🔹 Built-in Commands

  • exit -- Exit the shell\
  • cd -- Change current directory\
  • status -- Display exit status of the last foreground process

🔹 Execution & Redirection

  • Executes external commands via the exec family of functions\
  • Supports input (<) and output (>) redirection\
  • Run processes in foreground or background using &

🔹 Process & Signal Handling

  • Foreground/background process management\
  • Custom handling for:
    • SIGINT (Ctrl+C)\
    • SIGTSTP (Ctrl+Z)

🚀 Getting Started

Prerequisites

  • GCC or any C compiler

Build Instructions

# Clone repository
git clone https://github.com/weemsj/small_shell.git

# Enter project directory
cd smallsh

# Compile the program
gcc -o smallsh smallsh.c

Run the Shell

./smallsh

🖥️ Usage Examples

# Run in foreground
ls -l

# Run in background
sleep 10 &

# Redirect output
ls > output.txt

# Redirect input
sort < input.txt
  • Press Ctrl+C to send SIGINT\
  • Press Ctrl+Z to toggle foreground-only mode with SIGTSTP

🤝 Contributions

Contributions are welcome! Fork this repo, make improvements, and open a PR.


📜 License

This project is licensed under the MIT License -- see the LICENSE file for details.

About

small shell

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published