A minimal shell built in C as part of the ALX Software Engineering curriculum.
This project is a simplified version of a Unix shell. It supports executing basic commands, chaining commands with ;, and connecting commands using pipes |.
The goal is to gain a deep understanding of process creation, execution, file descriptors, and inter-process communication using system calls like fork, execve, pipe, and wait.
- Execute simple shell commands (e.g.,
ls,echo,pwd) - Support for command separators
; - Support for pipelines using
| - Built-in support for
cd - Proper error handling and exit codes
- Manual path resolution using
/bin/prefix
./microshell ls -l \| grep .c \; echo doneThis command will:
- List all files using
ls -l - Filter output through
grep .cusing a pipe - After the pipe finishes,
echo doneis executed
-
Parsing The program iterates over arguments and identifies separators
|and; -
Built-in Handling If the command is
cd, it is handled internally usingchdir() -
Execution
- A child process is created with
fork() - The command is run with
execve()(after prepending/bin/manually) - If piped, the input/output is redirected using
pipe()anddup2()
- A child process is created with
-
Error Handling Custom error messages are printed to
stderrif something fails -
Synchronization The parent waits for child processes with
waitpid()
microshell/
β
βββ microshell.c # All logic: parsing, execution, piping, etc.
βββ Makefile
βββ README.mdfork()execve()pipe()dup2()waitpid()chdir()write()malloc()
- Deep understanding of how Unix shells work internally
- Handling built-in commands manually
- Working with file descriptors and pipes
- Error handling and memory allocation in C
Made with β€οΈ by Samir β @Samir-Ouaammou Project part of ALX SE Program
This project is licensed under the MIT License - see the LICENSE file for details.