A simple command line interpreter written in C, taking the Bourne-Again Shell (bash) as inspiration.
Minishell is a small-scale shell that allows you to execute commands, manage files, and navigate the file system. It's one of our biggest projects in 42 school that involves writing a shell with basic features like command execution, pipelines, I/O redirection, and built-in commands.
- Prompt Display: Shows a prompt when waiting for a new command.
- Command History: Keeps a history of executed commands.
- Command Execution: Searches and runs executables based on the
PATHenvironment variable or using a relative/absolute path. - Hashing: Uses a simple hashtable to remember utility locations. Building a path for commands is necessary only once. If
PATHchanges, the hashtable gets automatically cleared. - Signal Handling: Properly handles
Ctrl-CandCtrl-\similar to bash.Ctrl-C: In parent process: displays a new prompt on a new line. DefaultSIGINTin children.Ctrl-\: Ignored in parent process. DefaultSIGQUITin children.Ctrl-D(this is actually not a signal, butEOF): can be used to delimit a heredoc or exit the shell.
- Quotes:
- Single quotes
': Prevent the shell from interpreting metacharacters in the quoted sequence. - Double quotes
": Prevent interpretation of metacharacters except for$(dollar sign).
- Single quotes
- Variable expansion:
- Handles the expansion of environment variables using
$. For anyNAME=valuepresent inenv,$NAMEin the command line gets replaced withvalue. Word splitting is performed onvalue(except for redirections).
- Handles the expansion of environment variables using
- Redirections:
<: Input redirection.>: Output redirection.<<(heredoc): Reads input until a delimiter is found.>>: Output redirection in append mode.
- Pipes: Supports the
|character to connect commands. - Exit Status: Supports
$?to get the exit status of the last executed command.
echowith-noption: prints its arguments.-nremoves the trailing newline.cdwith a relative or absolute path: changes directory.pwdwithout options: prints the name of the current/working directory.exportwith arguments: sets the value of a new or existing environment variable. Local assignment is also supported to an extent.unsetwith arguments: removes an existing variable from the environment list.envwithout options or arguments: displays the environment variable list.hashwithout options or arguments: displays all key/value pairs currently stored in the hashtable.exitwith one argument: exits the shell withargumentexit status.
Clone the repository, compile the source code & run the executable:
git clone https://github.com/rybarska/minishell_bonefire.git
cd minishell_bonefire
make
./minishell
Be aware that it will probably not run on your mac for our use of x86-64 inline Assembly.