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