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.
cd <directory>
— Change the current directory (~
and-
supported)pwd
— Print working directoryecho <text>
— Print to stdout; supports environment variable expansion (e.g.,$PATH
)env
— List all environment variablessetenv VAR=value
— Set or update environment variablesunsetenv <VAR>
— Remove an environment variablewhich <command>
— Locate command inPATH
.help
— Show available commandsexit
orquit
— Exit the shell gracefully
- External command execution using
fork()
,execvp()
, andwaitpid()
- 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
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 intoinput_parser.c
for simplicity.
- GCC or Clang
make
utility- Unix/Linux environment
cd /path/to/lbsh
make
This will generate the executable: ./lbsh
./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
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 |
- Piping (
|
) support - Redirection (
>
,>>
,<
) - Background process execution (
&
) - Command history
- Tab autocompletion
This project is open-source and available under the MIT License.
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.