Skip to content

This project is about creating a simple shell. Our own little bash. Team project with Orezek.

Notifications You must be signed in to change notification settings

m-bartos/42_minishell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42_minishell

This project is about creating a simple shell. Our own little bash with limited functionalities.

Team project with Orezek at 42Prague.

What kind of features our minishell have?

  • displays prompt as a bash - with path to current directory
  • working history
  • working redirections (<, >, >>), heredoc (<<), pipes (||)
  • execute commands as bash with argumets - ls, cat, head, git ...
  • launch executables - try launch ./minishell in ./minishell
  • handle environmental variables
  • woking expansion of environmental variables ($) as bash
  • handle CTRL-C, CTRL-D, CTRL-\ as bash
  • working builtins:
    • echo with option -n
    • cd with only a relative or absolute path
    • pwd with no options
    • export with no options
    • unset with no options
    • env with no options or arguments
    • exit with no options

What our minishell cannot do?

  • Cannot handle open quotes or open double quotes
  • Cannot handle special characters such as backslash \ or semicolon ;
  • NO BONUS - Cannot handle &&, || and wildcards *

How to run minishell

  • You have to have readline installed. If not, install it with
sudo apt install libreadline-dev
  • Make the minishell with command
Make
  • Run the program
./minishell

Examples

Aditional test cases

cat | cat - should hang and after pressing CTRL+C should end execution and show prompt again

cat /dev/urandom | head -5
/bin/ls src
/bin/pwd hello
/bin/date
/usr/bin/head -n 10 Makefile
/bin/grep # Makefile
/usr/bin/uname -a
/usr/bin/head Makefile
/usr/bin/tail Makefile

How to debug? Use valgrind!

Use this prompt to check for leaks, open fds, etc. (It requires minishell.supp file in minishell root directory)

valgrind -s --leak-check=full --show-reachable=yes --error-limit=no --suppressions=minishell.supp --trace-children=yes --track-fds=yes ./minishell
  • -s same as --show-error-list=yes that shows detected errors list and suppression count at exit
  • --leak-check=full shows a full list of memory leaks
  • --show-reachable=yes same as --show-leak-kinds=all that shows all kinds of memory leaks
  • --error-limit=no won't stop showing errors if too many
  • --suppressions=minishell.supp suppresses memory leaks from in-built functions (readline and add_history)
  • --trace-children=yes checks memory leaks in child process too
  • --track-fds=yes tracks open and closed file descriptors

What we learned during coding minishell

  • Understand bash better, how it works underneath
  • Better understanding of processes, forks, wait, waitpid, exit statuses, etc.
  • Learned what signals are and how to handle them
  • Learned to use static variable within clean functions to store a pointer to a struct for later use (see for example the exit_minishell() function)
  • Become more familiar with structs and linked lists

Contributors

  • m-bartos - parser - splitter, expander, heredoc; prompt construction
  • orezek - execution, built-ins, signals, environmental variables

Thanks and kudos

About

This project is about creating a simple shell. Our own little bash. Team project with Orezek.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published