minishell: writing my own shell

minishell: writing my own shell
Photo by Museums Victoria / Unsplash
In this project, the goal was to face problems people faced when Windows didn’t exist.

For a big project like that, thank god I don't need to do it alone 🙏
So I joined my friend Teo Rimize to develop it together.

We had to build a command-line interpreter 🤯 A shell that provides a command line user interface with capabilities such as command parsing and execution, signal handling, environment variable management, support for pipes and redirections, and implementation of built-in commands.

An example of a simple command in our minishell.

List of requirements

  • Have a working history
  • Handle  (single quote) which should prevent the shell from interpreting the meta-characters in the quoted sequence.
  • Handle " (double quote) which should prevent the shell from interpreting the meta-characters in the quoted sequence except for $ (dollar sign).
  • Implement redirections:
    • < should redirect input.
    • > should redirect output.
    • << should be given a delimiter, then read the input until a line containing the delimiter is seen. However, it doesn’t have to update the history!
    • >> should redirect output in append mode.
  • Implement pipes (| character). The output of each command in the pipeline is connected to the input of the next command via a pipe.
  • Handle environment variables ($ followed by a sequence of characters) which should expand to their values.
  • Handle $? which should expand to the exit status of the most recently executed foreground pipeline.
  • Handle ctrl-C, ctrl-D and ctrl-\ which should behave like in bash.
    • ctrl-C displays a new prompt on a new line.
    • ctrl-D exits the shell.
    • ctrl-\ does nothing.
  • Implement the following 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

Bonus features 💡

  • && and || with parenthesis for priorities.
  • Wildcards * work for the current working directory.
Example of a more complex prompt using a redirection to a file and the operator &&.

Grade 🏆

You can also check our code on my GitHub.

GitHub - marcioflaviob/minishell_42: Minishell group project. Marcio Flavio and Teo Rimize.
Minishell group project. Marcio Flavio and Teo Rimize. - marcioflaviob/minishell_42