Hey there, welcome to our Minishell project! 🎉
This is a simplified shell program developed as part of the curriculum at the 42 School. The goal of this project is to recreate a basic Unix shell with features that mimic the behavior of a typical shell, while also offering the flexibility to extend it with custom commands and functionalities.
Minishell serves as a great exercise in system programming, process management, and working with signals, all within the context of Unix-based systems. Whether you're interested in learning how shells work under the hood or you're just looking for a fun project to play around with, Minishell has you covered!
This project is intended to be a learning exercise for 42 students. Please do not copy, fork, or steal code from this repository to submit as your own. The aim of the project is to help you learn, not just complete the assignment. If you’re stuck, work through the problem, ask for help, or discuss it with peers, but do not simply use other students' solutions. We believe in the value of learning through challenges, and that’s the only way you’ll truly grow and succeed at 42. Let’s keep it fair and fun!
Greetings Andreas and Volodymyr ✌️
The minishell program requires the following to compile and run:
-
A Unix-like operating system (e.g., Linux, macOS)
-
GNU Make
-
GCC or Clang
-
Readline library (for command-line input handling)
If you do not want to deal with dependencies than using this link will be the easiest way to try the minishell using docker.
git clone https://github.com/atdeters/minishell.git && cd minishell && docker build -t msh . && docker run -it mshNote:
The alias- (.msh_alias) and history- (.msh_history) files will not be stored when exiting and reopening this docker image.
Use the following installation to try those features.
sudo apt update && sudo apt install -y build-essential libreadline-dev && git clone https://github.com/atdeters/minishell.git && cd minishell && makebrew install readline && git clone https://github.com/atdeters/minishell.git && cd minishell && makeOnce compiled, start the shell with
./minishellTo run minishell in single-command mode run it with the -s flag.
It will execute the command and exit afterwards.
./minishell -s [command]For displaying a usage file in the terminal run it with the -h flag
./minishell -h- Environment Variable Management: Easily access and modify environment variables.
- Signal Handling: Properly handles the signals
SIGINTandSIGQUIT. - Pipes and Redirections: Supports piping between commands and file redirection.
|: Connects the output of one command to the input of the next.>: Redirects the output to a file.>>: Redirects the output to a file in append mode.<: Redirects the input from a file.<< DELIMITER: Creates a temporary here document, which is terminated by the specifiedDELIMITER.
- Forking and Execution: Executes external programs and commands.
- Quotes Handling: Properly handles strings with quotes:
- Single Quotes (
'): The characters inside single quotes are treated literally, meaning no expansion occurs (including environment variables). - Double Quotes (
"): The characters inside double quotes are treated as a string, and environment variables will be expanded. For example,$HOMEwill be expanded to the user's home directory.
- Single Quotes (
- Built-in Commands: Includes essential commands like
cd,echo,exit,pwd, and more! - Bonus Features:
- Persistent History: Automatically saves command history in a file.
- Persistent Aliases: Automatically saves aliases in a file.
- Current Working Directory Display: Displays the current working directory in the prompt.
- Git Repository Info: Displays the current git repository (if applicable) in the prompt.
Set or display aliases for commands.
Usage: alias [flags] alias[=expansion]
alias(without arguments) displays all active aliases.alias -rremoves alias permanently.alias "st= git status"sets "st" as alias for "git status"alias stdisplays the corresponding alias with its expansion
Display a short manual for built-in commands.
Usage: biman [builtin name]
Change the shell working directory.
Usage: cd [directory]
cd(without arguments) changes to the home directory.cd ~also changes to the home directory.cd ..moves up one directory.cd /usr/binmoves to /usr/bin.
Prints a line of text to the standard output.
Usage: echo [-n] [string...]
-n: Omits the trailing newline.
Displays the current environment variables.
Usage: env
Exits the shell with an optional exit code.
Usage: exit [status]
- If no status is given, it exits with the status of the last executed command.
Set or display environment variables.
Usage: export name[=value]
export(without arguments) lists all exported variables in alphabetical order.export VAR=value: Sets an environment variable.
Prints the absolute path of the current directory.
Usage: pwd [-c]
-c / --clean: Only displays the current folder (without path).
Removes environment variables.
Usage: unset [VAR]