VSH (V Shell) is a lightweight, custom Unix shell implementation written in C. It provides basic shell functionality with a clean, colorized interface and supports both built-in commands and external program execution.
- Interactive Command Line: Colorized prompt showing username, hostname, and current directory
- Built-in Commands:
cd,help,exit, andhistorycommands with full functionality - External Program Execution: Run any system command or program with argument support
- I/O Redirection: Full support for input (
<), output (>), and append (>>) redirection - Pipe Support: Chain commands together using pipes (
|) for powerful command composition - Environment Variables: Access and use environment variables (e.g.,
$HOME,$PATH,$USER) - Command History: Persistent command history stored in
~/.vsh_historywith readline integration - Signal Handling: Proper handling of SIGINT (Ctrl+C) to interrupt running processes
- Home Directory Support: Navigate using
~shorthand for home directory expansion - Memory Management: Robust allocation and cleanup of dynamic memory with error handling
vsh/
├── include/
│ ├── builtins.h
│ ├── colors.h
│ ├── executor.h
│ ├── parser.h
│ ├── shell.h
│ ├── signals.h
│ └── utils.h
├── src/
│ ├── builtins.c
│ ├── executor.c
│ ├── main.c
│ ├── parser.c
│ ├── shell.c
│ ├── signals.c
│ └── utils.c
├── obj/
├── Makefile
└── vsh
- GCC compiler
- GNU Readline library
- POSIX-compliant Unix system (Linux, macOS, etc.)
Ubuntu/Debian:
sudo apt-get install gcc libreadline-devCentOS/RHEL:
sudo yum install gcc readline-develFedora:
sudo dnf install gcc readline-develmacOS:
# Install Xcode command line tools
xcode-select --install
# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install readline
brew install readlineArch Linux:
sudo pacman -S gcc readlinegit clone https://github.com/Vatsalj17/vsh.git
cd vsh
make
sudo make installThis will:
- Build the
vshexecutable - Install it to
/usr/local/bin/vsh(accessible system-wide)
Run the shell:
./vsh # If built locally
# or
vsh # If installed system-wideYou'll see a colorized prompt in the format:
username@hostname - current_directory took time status_code
⊱
cd [directory]: Change directory (supports~for home directory)help: Display available commands and shell featuresexit: Exit the shell gracefullyhistory: Display command history (stored in~/.vsh_history)
Any system command or program can be executed with full support for advanced shell features:
Basic Commands:
ls -la
grep "pattern" file.txt
gcc -o program program.c
python script.pyI/O Redirection:
ls > file_list.txt # Redirect output to file
cat < input.txt # Redirect input from file
echo "text" >> log.txt # Append output to filePipes:
ls -la | grep ".txt" # List files and filter for .txt files
cat file.txt | sort | uniq # Sort and remove duplicates
ps aux | grep "vsh" # Find vsh processesEnvironment Variables:
echo $HOME # Display home directory
echo $PATH # Display PATH variable
ls $HOME/Documents # Use variables in commands- Ctrl+C (SIGINT): Interrupts the currently running command without exiting the shell
- Ctrl+D (EOF): Exits the shell gracefully
- Parser (
parser.c): Tokenizes user input into command arguments - Executor (
executor.c): Handles command execution (built-ins vs external programs) - Shell Interface (
shell.c): Manages the interactive prompt and user input - Built-ins (
builtins.c): Implements built-in shell commands - Utilities (
utils.c): Helper functions for user info and path management - Signal Handling (
signals.c): Manages signal handling for process control
- Process Management: Uses
fork()andexecvp()for external command execution - Path Resolution: Supports both absolute paths and home directory shortcuts
- Memory Safety: Proper allocation, deallocation, and error handling
- Color Support: ANSI color codes for enhanced visual experience
To remove VSH from your system:
sudo make uninstallTo clean build artifacts:
make clean- No background process support (
&) - No command substitution (
`command`or$(command)) - No shell scripting support (if/while/for loops)
- Limited tab completion (relies on readline's default behavior)