Skip to content

ninetendo59/minishell_hetan-nbinnazl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minishell

A hell project from 42

🌟 Features

  • Interactive shell with basic prompt functionality
  • Execution of binary commands (e.g., /bin/ls)
  • Built-in commands:
    • cd: Change the current working directory
    • echo: Display a line of text
    • env: Show environment variables
    • exit: Exit the shell
    • export: Set environment variables
    • pwd: Print the current directory
    • unset: Remove environment variables
  • Input and output redirection (<, >, >>)
  • Support for pipes (|) to chain commands
  • Signal handling for Ctrl+C, Ctrl+D, and Ctrl+Z
  • Environment variable expansion (e.g., $PATH, $HOME)
  • Error handling for invalid commands or syntax

📂 Project Structure

/minishell
├───inc
|   ├───ft_printf.h
|   ├───get_next_line.h
|   ├───libft.h
|   └───minishell.h
├───libft
|   └───...//soon will publish libft libraries
├───shell
|   ├───builtins
|   |   ├───cd.c
|   |   ├───echo.c
|   |   ├───env.c
|   |   ├───exit.c
|   |   ├───export.c
|   |   ├───pwd.c
|   |   └───unset.c
|   ├───env
|   |   ├───env.c
|   |   ├───get.c
|   |   ├───shlvl.c
|   |   └───sort.c
|   ├───exec
|   |   ├───bin.c
|   |   ├───builtin.c
|   |   └───cmd.c
|   ├───parse
|   |   ├───expansion.c
|   |   ├───line.c
|   |   ├───token.c
|   |   └───token_data.c
|   └───utils
|       ├───expansion.c
|       ├───fd.c
|       ├───free.c
|       ├───gnl.c
|       ├───minishell.c
|       ├───parse.c
|       ├───token.c
|       ├───type.c
|       └───utils.c
├───src
|   ├───main.c
|   ├───rd_cmd.c
|   └───signalling.c
├───Makefile
└───README.md

🎓 Learning Objectives

  • Understanding process creation and management (fork, execve, wait, pipe)
  • Mastering file I/O and redirections
  • Implementing a custom shell environment
  • Handling user input and signal interruptions

🤝 Collaborator

@nizarsyahmi37 - Main contributor, bash interface designer @ninetendo59 - Create minishell "skeletal" structure, norminette checking, debugging completed code (fixing leaks, uninitialised value, refactor and restructure code), sanity testing.

🤔 What is the difference between Shell and Terminal?

🖥️ Terminal

  • A window or interface that provides a space to execute commands via a shell.
  • Acts as a container for the shell to run.

🐚 Shell

  • It is a command interpreter or environment where you execute commands.
  • Offers scripting, command history, and access to system features.

⚖️ Choice of function for taking input

Function Pros Cons
get_next_line(int fd)
  • zero leaks (if you implement it correctly)
  • mutex based
  • recycle and minor code modification
  • efficient, which designed to be directly take input from fd.
  • customisible in terms on BUFFER_SIZE control
  • Unable to use history and require to implement history by your own
  • low level control, which may require extra and tedious implementation.
readline (const char *prompt)
  • Easy usage.
  • high level control, which is user friendly, offers line by line input reading.
  • Thread safe, as it handles input buffer internally.
  • Causes leaks (Minishell project does not requires you to handle the leaks, but other leaks that is not caused by this function is not tolerated)
  • performance wise may not be optimised for low level or socker i/o.
  • In my opinion, using readline() is the easiest way to complete your minishell compared to get_next_line().
  • If you are perfectionist, why not just go ahead to use get_next_line()?

⍼ Leak Check command

valgrind --leak-check=full ./minishell

📖 Further references

  1. https://m4nnb3ll.medium.com/minishell-building-a-mini-bash-a-42-project-b55a10598218
  2. https://www.youtube.com/watch?v=yTR00r8vBH8
  3. https://medium.com/@muxanz/how-the-shell-works-internally-when-entering-a-command-42f08458870
  4. https://medium.com/@nyangaresibrian/simple-shell-b7014425601f
  5. https://42-cursus.gitbook.io/guide/rank-03/minishell

About

Minishell but startup

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors