Skip to content

samir-ouaammou/Micro-Shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 

Repository files navigation

πŸ‘š Microshell


A minimal shell built in C as part of the ALX Software Engineering curriculum.


πŸ“š Project Description


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.


πŸš€ Features


  • 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

βš™οΈ Usage


./microshell ls -l \| grep .c \; echo done

This command will:

  1. List all files using ls -l
  2. Filter output through grep .c using a pipe
  3. After the pipe finishes, echo done is executed

πŸ”§ How it works


  1. Parsing The program iterates over arguments and identifies separators | and ;

  2. Built-in Handling If the command is cd, it is handled internally using chdir()

  3. 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() and dup2()
  4. Error Handling Custom error messages are printed to stderr if something fails

  5. Synchronization The parent waits for child processes with waitpid()


πŸ“ File Structure


microshell/
β”‚
β”œβ”€β”€ microshell.c       # All logic: parsing, execution, piping, etc.
β”œβ”€β”€ Makefile
└── README.md

πŸ“Œ System Calls Used


  • fork()
  • execve()
  • pipe()
  • dup2()
  • waitpid()
  • chdir()
  • write()
  • malloc()

🧐 What I Learned


  • 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

πŸ‘¨β€πŸ’» Author


Made with ❀️ by Samir β€” @Samir-Ouaammou Project part of ALX SE Program


πŸ“ License


This project is licensed under the MIT License - see the LICENSE file for details.

About

Microshell is a mini shell built in C as part of ALX. It supports basic commands, cd, pipes |, and command chaining with ;, using low-level system calls like fork, execve, and pipe.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages