Skip to content

Slim-Hady/Mini_Shell

Repository files navigation

Mini Shell

sequence diagram

image

A simple Unix-like shell implementation using Lex/Flex and Yacc/Bison.

Building the Project

To build the minishell executable, run:

make

This will:

  1. Generate the parser from shell.y using Bison
  2. Generate the scanner from shell.l using Flex
  3. Compile all sources into the minishell executable

Running the Shell

After building, run the shell with:

./minishell

You will see the minishell> prompt where you can enter commands.

Implemented Features

1. Basic Command Execution

  • Execute external programs with arguments
  • Uses PATH environment variable to locate executables
  • Example: ls -l /tmp

2. Built-in Commands

  • cd [dir]: Change directory
  • pwd: Print working directory
  • exit: Exit the shell

3. Environment Variables

  • Variable expansion using $VAR syntax
  • Variable assignment using NAME=value
  • Example: echo $HOME

4. Input/Output Redirection

  • Input redirection: cmd < file
  • Output redirection: cmd > file
  • Append redirection: cmd >> file
  • Example: cat < input.txt > output.txt

5. Pipelines

  • Single pipeline support: cmd1 | cmd2
  • Example: ls -l | grep txt

6. Background Execution

  • Run commands in background using &
  • Example: sleep 10 &

7. Comments

  • Lines starting with # are treated as comments

8. Quoted Strings

  • Support for double quotes: "string with spaces"
  • Support for single quotes: 'another string'

Usage Examples

# Simple commands
SlimHady'sShell> ls -la
SlimHady'sShell> pwd
SlimHady'sShell> cd /tmp

# Environment variables
SlimHady'sShell> HOME=/home/user
SlimHady'sShell> echo $HOME

# Redirection
SlimHady'sShell> cat file.txt > output.txt
SlimHady'sShell> cat >> output.txt < input.txt

# Pipelines
SlimHady'sShell> ls -l | grep .txt
SlimHady'sShell> cat file.txt | wc -l

# Background execution
SlimHady'sShell> sleep 5 &

# Exit the shell
SlimHady'sShell> exit

Known Limitations

  1. Only single pipelines are supported (not multiple pipes like cmd1 | cmd2 | cmd3)
  2. No support for complex shell features like:
    • Command substitution
    • Wildcards/globbing
    • Job control (fg, bg, jobs)
    • Signal handling (Ctrl-C)
    • History
    • Tab completion

Error Handling

The shell handles various error conditions:

  • Invalid commands display "command not found"
  • Failed directory changes display appropriate error messages
  • Invalid file redirections display error messages
  • Syntax errors are caught and the shell continues running

Cleaning Up

To remove all generated files and the executable:

make clean

Files

  • shell.l: Lex scanner specification
  • shell.y: Yacc parser specification with execution logic
  • Makefile: Build configuration
  • README.md: This file

Requirements

  • GCC compiler
  • Flex (or Lex)
  • Bison (or Yacc)
  • POSIX-compliant system (Linux recommended)

screens :

image

About

Mini shell

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors