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 commandsexitorquitβ 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.cwas merged intoinput_parser.cfor simplicity.
- GCC or Clang
makeutility- Unix/Linux environment
cd /path/to/lbsh
makeThis will generate the executable: ./lbsh
./lbshYouβ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.