This project is a core part of the 42 school curriculum. The goal of minishell is to create a simple, functional shell, similar to bash or zsh. This project teaches fundamental concepts of process management, command execution, and environment handling.
The shell should be able to:
- Display a prompt and wait for user input.
- Execute external commands and programs.
- Handle a variety of built-in commands.
- Manage environment variables.
- Support command redirection (
<,>). - Support command pipes (
|).
The minishell program operates in a continuous loop:
- Read: The program reads a command line entered by the user from standard input.
- Parse: The command line is tokenized and parsed into a command and its arguments. This stage handles special characters like pipes, redirections, and quotes.
- Execute: Based on the parsed command, the program takes action:
- If the command is a built-in (e.g.,
cd,echo,export), the shell's own functions are called. - If it's an external command, the shell forks a new process, and the child process uses
execveto execute the command. The parent process waits for the child to finish.
- If the command is a built-in (e.g.,
- Loop: After the command is executed, the program frees all allocated memory and returns to the read stage, displaying the prompt again.
echowith option-ncdwith only a relative or absolute pathpwdexportunsetenvexit
To compile and run minishell, you will need a Makefile.
You can compile your program using the provided Makefile.
makeOnce compiled, you can run the executable from your terminal.
./minishell$ ls -l
$ echo "Hello, World!" > file.txt
$ cat file.txt
$ env | grep PATH