Welcome to RainbowShell, my educational but powerful custom Unix shell written in C. RainbowShell implements pipes, redirections, logical operators, subshells, and background jobs while also featuring a rainbow/gradient greeting message (builtes color.h
library).
Note: This is a project for the 3rd semester at CMC MSU (summarizing skills of systems programming, process handling, shell scripting concepts).
- Rainbow Greeting
When you launch RainbowShell, you’re greeted with a colorful gradient welcome message. Because, who don't want to meet a rainbow 🌈 ?
-
Custom Command Parser
- Supports multi-stage pipelines:
cmd1 | cmd2 | cmd3
- Understands logical operators:
&&
,||
- Sequential execution:
cmd1 ; cmd2
- Subshells:
(cd / && ls -l)
- Redirections:
< file
,> file
,>> file
- Background tasks:
cmd &
- Supports multi-stage pipelines:
-
Built-in Commands
cd <dir>
: change directory (built-in, because changing directories in a child process has no effect on the parent)
-
Error Handling
- Lexer and parser produce meaningful, color-highlighted error messages (typos, missing quotes, etc).
- Handles partial command failures in pipelines (ex. if the last command in a pipeline fails, subsequent
&&
sections won’t run).
-
Background Jobs
- Run commands asynchronously with
&
. - Automatically ignores
SIGINT
(Ctrl-C) in the background job so it won’t be interrupted. - Prevents zombie processes via
waitpid
.
- Run commands asynchronously with
-
Subshell & Grouping
- Parentheses
( ... )
create a new job in a subshell.
Example:(cd /; ls); pwd
- You can group multiple commands, run them in the background, or combine with logical operators.
- Parentheses
-
Extensible Architecture
- Separation of lexer, parser, and executor.
- Because of it future features or built-ins can be easily added.
-
Clone this repository:
git clone https://github.com/estnafinema0/RainbowShell.git cd RainbowShell/shell
-
Compile using
make
:make
Now we have executable
Rainbowshell
. -
Run RainbowShell:
./Rainbowshell
Now you are open to type any commands as in a standard Unix shell.
shell> echo "Hello World"
Use Ctrl-C to send an interrupt signal to foreground commands. If a command is run in the background (using &
), it won’t be interrupted by Ctrl-C (as it should be in a usual shell!).
-
main.c
Entry point for RainbowShell. Handles signals (SIGINT
andSIGCHLD
), prints the rainbow greeting, and starts the main interactive loop. -
parser.c / parser.h
Contains the logic for parsing command lines into a structured form (Job
andCommand
objects). Handles operators like&&
,||
,|
,;
,&
, as well as subshell grouping( ... )
. -
lexer.c / lexer.h
Breaks the command line into tokens (TOKEN_WORD
,TOKEN_OPERATOR
, etc.). Also handles quoted strings and error checking for unclosed quotes. -
executor.c / executor.h
Executes commands by forking processes. Implements:- Pipelines (
|
) - Sequential commands (
;
) - Conditional commands (
&&
,||
) - Subshells
- Redirections (
<
,>
,>>
) - Background jobs (
&
)
- Pipelines (
-
builtins.c / builtins.h
Built-in commands such ascd
. -
colors.c / colors.h
Provides color/gradient print utilities. Theprint_rainbow_text
function produces the signature rainbow greeting. -
structures.h
Defines the primary data structures (Command
,Job
,OperatorType
) used across the shell. -
makefile
Contains build rules. Simply runmake
.
Here are some commands to showcase RainbowShell’s broad functionality:
-
Subshell & Sequential
(cd /; pwd); pwd
- Changes directory to
/
, prints it, then returns to the parent shell and prints its current directory.
- Changes directory to
-
Conditional Execution
(false && echo "Skipped 1") || (echo "Fallback 1" && echo "Part of fallback")
false
fails, so&&
chain is skipped;||
triggers the fallback commands.
-
Background Task with Redirection
echo "Background task" > output.txt & cat output.txt
- The
echo
runs in the background, while the shell immediately proceeds tocat output.txt
.
- The
-
Pipeline
echo "hello" | grep "hello" && echo "Pipeline succeeded" || echo "Pipeline failed"
- If
grep "hello"
finds the text, the&&
chain continues.
- If
-
Multiple Steps with Conditionals
ls non_existent_dir && echo "This should not print" || echo "Directory not found"
- Fails on the nonexistent directory, triggers the
||
fallback.
- Fails on the nonexistent directory, triggers the
-
Process Listing and Subshell
ps; ls; (cd .. ; ls; ps) && ls && ps
- Shows how a subshell can change directory without affecting the parent shell.
-
Background Sleep
sleep 5 & echo "Background process test"
sleep
runs in the background, while RainbowShell continues to the next command.
If you type &
in the end of the command, it will launch in the background:
- Non-blocking background: The shell is immediately ready for the next command.
- No Zombie Processes: RainbowShell calls
waitpid
appropriately. - Ignored SIGINT: Background jobs ignor
Ctrl-C
from the main terminal.
Thank you for checking out RainbowShell! Enjoy the rainbow!🌈