Skip to content

belohith/lbshell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐚 LBShell – A Custom UNIX Shell in C

LBShell (Little Bear Shell) is a custom-built command-line interpreter developed in C as a systems-level project to explore shell architecture, Unix system calls, and command parsing. It replicates core functionalities of standard shells like bash and zsh, while offering a clean, extendable codebase.

πŸ› οΈ Built from scratch to understand how shells work under the hood β€” from command parsing to process execution.


πŸš€ Features

βœ… Built-in Commands

  • cd <directory> β€” Change the current directory (~ and - supported)
  • pwd β€” Print working directory
  • echo <text> β€” Print to stdout; supports environment variable expansion (e.g., $PATH)
  • env β€” List all environment variables
  • setenv VAR=value β€” Set or update environment variables
  • unsetenv <VAR> β€” Remove an environment variable
  • which <command> β€” Locate command in PATH
  • .help β€” Show available commands
  • exit or quit β€” Exit the shell gracefully

βš™οΈ Core Functionalities

  • External command execution using fork(), execvp(), and waitpid()
  • Custom tokenizer & parser built without using strtok(), to deeply understand tokenization
  • String utilities: Custom implementations of strlen, strcpy, strchr, strdup, etc.
  • Error handling for invalid commands, failed directory changes, permission issues, and more

πŸ“ Project Structure

lbsh/
β”œβ”€β”€ Makefile
└── src/
    β”œβ”€β”€ main.c           # Shell entry point and REPL loop
    β”œβ”€β”€ input_parser.c   # Command parsing and tokenization
    β”œβ”€β”€ builtins.c       # Built-in command implementations
    β”œβ”€β”€ executor.c       # Process execution logic
    └── lbsh.h           # Header declarations

πŸ”„ Legacy helpers.c was merged into input_parser.c for simplicity.


πŸ”§ Build & Run

Prerequisites

  • GCC or Clang
  • make utility
  • Unix/Linux environment

🧱 Compilation

cd /path/to/lbsh
make

This will generate the executable: ./lbsh

▢️ Running LBShell

./lbsh

You’ll see the interactive prompt:

[LBShell]>

Then you can try commands like:

[LBShell]> echo Hello, LBShell!
Hello, LBShell!

[LBShell]> which ls
/usr/bin/ls

[LBShell]> setenv MY_VAR=awesome
[LBShell]> echo $MY_VAR
awesome

πŸ› οΈ Makefile Commands

Command Description
make Compile and build the project
make clean Remove intermediate .o files
make fclean Remove all build files + the lbsh binary
make re Clean and rebuild from scratch

🌱 Planned Enhancements

  • Piping (|) support
  • Redirection (>, >>, <)
  • Background process execution (&)
  • Command history
  • Tab autocompletion

πŸ“œ License

This project is open-source and available under the MIT License.


πŸ’‘ Why This Project?

LBShell was built as an educational deep dive into Unix systems programming.
It demonstrates understanding of low-level process control, memory management, string manipulation, and command execution β€” all built without relying on high-level libraries.

About

LBShell: A custom shell written in C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published