A simple shell implementation in C that mimics the behavior of bash, created as part of the 42 School curriculum.
- Overview
- Features
- Requirements
- Installation
- Usage
- Built-in Commands
- Error Handling
- Project Structure
- Testing
- Authors
- License
Minishell is a simplified version of a Unix shell that provides basic command-line functionality. This project demonstrates understanding of process management, file descriptors, signal handling, and parsing in C.
Example of minishell running basic commands
- Prompt Display: Shows a prompt when waiting for new commands
- Command History: Working history of executed commands
- Executable Search: Finds and launches executables based on PATH variable or relative/absolute paths
- Global Variables: Minimal use of global variables (only for signal handling)
- Quote Handling:
- Single quotes (
') prevent interpretation of meta-characters - Double quotes (
") prevent interpretation except for$
- Single quotes (
- Redirections:
<redirects input>redirects output<<heredoc (reads input until delimiter)>>redirects output in append mode
- Pipes:
|character pipes output of each command to input of next command - Environment Variables:
$followed by variable name expands to variable value - Exit Status:
$?expands to exit status of most recently executed foreground pipeline - Signal Handling:
ctrl-Cdisplays new prompt on new linectrl-Dexits the shellctrl-\does nothing
echowith option-ncdwith only relative or absolute pathpwdwith no optionsexportwith no optionsunsetwith no optionsenvwith no options or argumentsexitwith no options
- Language: C
- Compiler: gcc with flags
-Wall -Wextra -Werror - External Libraries:
- readline (for command-line editing and history)
- Standard C library functions
- System: Unix-like operating system (Linux, macOS)
- Clone the repository:
git clone <repository-url>
cd minishell- Compile the project:
make- Run the executable:
./minishell$ ls -la
$ echo "Hello World"
$ pwd
$ cd /path/to/directory$ echo "Hello" > file.txt
$ cat < file.txt
$ echo "World" >> file.txt
$ cat << EOF
heredoc content
EOF$ ls -la | grep "txt"
$ cat file.txt | wc -l$ echo $HOME
$ echo $USER
$ export MY_VAR="value"
$ echo $MY_VAR$ ls non_existent_file
$ echo $?Displays a line of text.
$ echo "Hello World"
$ echo -n "No newline"Changes the current directory.
$ cd /path/to/directory
$ cd ..
$ cd ~Prints the current working directory.
$ pwdSets environment variables.
$ export VAR="value"Removes environment variables.
$ unset VARDisplays environment variables.
$ envExits the shell.
$ exit
$ exit 42The shell handles various error conditions gracefully:
- Command not found: Displays appropriate error message
- Permission denied: Shows permission error for non-executable files
- Invalid redirections: Handles file access errors
- Syntax errors: Reports parsing errors for invalid command syntax
- Memory allocation: Proper cleanup on memory allocation failures
minishell/
├── src/
│ ├── main.c
│ ├── parser/
│ ├── executor/
│ ├── builtins/
│ ├── signals/
│ └── utils/
├── includes/
│ └── minishell.h
├── libft/
├── Makefile
├── screenshot.png
└── README.md
- Test all built-in commands
- Verify pipe functionality with multiple commands
- Test all redirection types
- Check quote handling (single and double)
- Verify environment variable expansion
- Empty commands
- Multiple consecutive spaces/tabs
- Unclosed quotes
- Invalid redirections
- Signal handling during command execution
- Run with valgrind to check for memory leaks
- Test extensive command sequences
- Verify proper cleanup on exit
The screenshot above shows minishell in action, demonstrating various features including command execution, built-in commands, and proper prompt display.
This project is part of the 42 School curriculum and is subject to the school's academic policies.
Note: This implementation focuses on the mandatory requirements of the minishell project. Advanced features like logical operators (&&, ||), wildcards, or advanced job control are not included in this version.
