This project is a custom shell implementation in C that supports standard shell commands, sequential and parallel execution, I/O redirection, and pipelines. It also handles signals (Ctrl+C
, Ctrl+Z
) gracefully and provides a basic interactive prompt.
-
Basic command execution
-
Runs external commands like
ls
,pwd
,echo
, etc. -
Built-in support for:
cd
(change directory)exit
(terminate the shell)
-
-
Sequential execution (
##
)- Commands separated by
##
run one after another.
ls ## pwd ## date
- Commands separated by
-
Parallel execution (
&&
)- Commands separated by
&&
run in parallel.
ls && date && echo "Done"
- Commands separated by
-
Output redirection (
>
)- Redirects standard output of a command to a file.
ls > out.txt
-
Pipelines (
|
)- Connects multiple commands with pipes.
ls -l | grep ".c" | wc -l
-
Signal handling
Ctrl+C (SIGINT)
andCtrl+Z (SIGTSTP)
donβt kill the shell β they just refresh the prompt.
.
βββ myshell.c # Main source code
βββ README.md # Documentation
Use gcc
to compile:
gcc myshell.c -o myshell
Run the shell:
./myshell
Youβll see a prompt showing the current directory:
/home/user$
/home/user$ ls
/home/user$ cd Documents
/home/user/Documents$ ls && date
/home/user/Documents$ ls ## pwd
/home/user/Documents$ ls -l | grep ".txt"
-
Parsing
- Custom
parseInput()
function to tokenize input by delimiters (&&
,##
,>
,|
).
- Custom
-
Execution
- Uses
fork()
,execvp()
, andwaitpid()
for process handling.
- Uses
-
Parallel Execution
- Forks multiple processes and waits for all.
-
Sequential Execution
- Executes commands one after another.
-
Redirection
- Uses
open()
,dup2()
to redirect standard output.
- Uses
-
Pipelines
- Sets up multiple pipes and forks processes in a chain.
-
Signal Handling
- Catches
SIGINT
andSIGTSTP
to refresh the prompt instead of terminating the shell.
- Catches