|
1 |
| -to test run: |
| 1 | +English | [日本語](./docs/Readme-ja.md) | [繁體中文](./docs/Readme-zh.md) |
| 2 | + |
| 3 | + |
| 4 | +# Minishell - As Beautiful as a Shell |
| 5 | +<p align="left"> |
| 6 | + <img src="https://img.shields.io/badge/-C-213a70.svg?logo=C&style=flat"> |
| 7 | + <img src="https://img.shields.io/badge/-Linux-ea5520.svg?logo=linux&style=flat"> |
| 8 | + <img src="https://img.shields.io/badge/Subject_Version-8.02-3E72BC.svg"> |
| 9 | + <img src="https://github.com/cuajarsaki/minishell/actions/workflows/test.yml/badge.svg" alt="minishell"> |
| 10 | +</p> |
| 11 | +<p align="center"> |
| 12 | + <img src="https://github.com/cuajarsaki/minishell/blob/a5fad336ac54386db5af09fb4ca2ee568a382864/docs/minishell_icon.png" alt="Minishell 42 project badge" style="width:10%;"/> |
| 13 | +</p> |
| 14 | +Minishell is a mini shell project written in C that mimics the basic functionalities of Bash. |
| 15 | +While learning about process management, file descriptors, and signal handling, We built our own command-line interface. |
| 16 | +We paid special attention to accurately replicating bash's behavior regarding exit status values and error messages, ensuring that our shell responds to errors in a consistent and familiar way for users accustomed to bash. |
| 17 | + |
| 18 | +## Features |
| 19 | +- **Interactive Prompt:** Displays a prompt for user input. |
| 20 | +- **Command Execution:** Runs commands using the `PATH` variable or relative/absolute paths. |
| 21 | +- **Redirections & Pipes:** Supports input/output redirection (`<`, `>`, `<<`, `>>`) and piping (`|`). |
| 22 | +- **Environment Variables:** Expands variables (e.g., `$VAR` and `$?` for exit status). |
| 23 | +- **Signal Handling:** Properly responds to Ctrl-C, Ctrl-D, and Ctrl-\. |
| 24 | + |
| 25 | +## Built-in Commands |
| 26 | +| Command | Description | |
| 27 | +|-----------|------------------------------------------------------------------------------------------| |
| 28 | +| `echo` | Prints text to the terminal (supports `-n` option to omit newline). | |
| 29 | +| `cd` | Changes the current directory | |
| 30 | +| `pwd` | Displays the current working directory. | |
| 31 | +| `export` | Sets environment variables. | |
| 32 | +| `unset` | Removes environment variables. | |
| 33 | +| `env` | Lists all environment variables. | |
| 34 | +| `exit` | Exits the shell. |
| 35 | + |
| 36 | +## Norminette Compliance |
| 37 | +This project strictly adheres to the 42 School Norminette rules (v3.3.55). The Norminette enforces a consistent coding style across all C projects at 42, including: |
| 38 | + |
| 39 | +- 25 lines maximum per function |
| 40 | +- 80 characters maximum per line |
| 41 | +- Only 5 functions maximum per file |
| 42 | +- Specific variable declaration and naming conventions |
| 43 | +- Restricted use of standard library functions |
| 44 | +- Structured function header format |
| 45 | +- No for loops, switch statements, or do-while loops |
| 46 | +- Required use of tabs for indentation |
| 47 | + |
| 48 | +All code in this repository passes the official 42 Norminette validator without errors. |
| 49 | + |
| 50 | +><img src="https://github.com/cuajarsaki/minishell/blob/a5fad336ac54386db5af09fb4ca2ee568a382864/docs/norminette.png" alt="grade" style="width:40%;"/> |
| 51 | +
|
| 52 | +## Final grade |
| 53 | +<img src="https://github.com/user-attachments/assets/765ec3c2-7927-4a92-b718-ec39fc93c64d" alt="grade" style="width:20%;"/> |
| 54 | + |
| 55 | +Validated : 09/03/2025 |
| 56 | + |
| 57 | +Mandatory part : 100/100 |
| 58 | + |
| 59 | +Bonus : 0/15 |
| 60 | + |
| 61 | + |
| 62 | +## Flowchart of Main |
| 63 | + |
| 64 | +```mermaid |
| 65 | + |
| 66 | +flowchart LR |
| 67 | + A[Start main] --> B[Init env_list] --> C[Setup terminal] --> D[run_shell] --> E[Cleanup] --> F[Exit] |
| 68 | + |
| 69 | + D --> G[run_shell loop] |
| 70 | + G --> H[Handle signals] --> I[Get input] --> J{any Input?} |
| 71 | + J -->|No| G |
| 72 | + J -->|Yes| K[parse_ast] --> L[exec_ast] --> M[free_ast] --> G |
| 73 | +``` |
| 74 | + |
| 75 | +## Flowchart of Execution Part |
| 76 | +```mermaid |
| 77 | +
|
| 78 | +graph TD |
| 79 | + A[exec_ast] --> B[exec_command_group] |
| 80 | + B --> C{is no command?} |
| 81 | + C -->|Yes| D[return 0] |
| 82 | + C -->|No| E{is single command?} |
| 83 | + E -->|Yes| F{is exit/cd/unset/export?} |
| 84 | + F -->|Yes| G[exec_cmd_builtin] |
| 85 | + F -->|No| H[fork] |
| 86 | + H -->|Child| I[exec_child_process] |
| 87 | + H -->|Parent| J[exec_parent] |
| 88 | + E -->|No| K[process_command] |
| 89 | + K --> L[setup_pipe_and_fork] |
| 90 | + L --> M[fork] |
| 91 | + M -->|Child| N[execute_child] |
| 92 | + M -->|Parent| O[setup_parent_pipe] |
| 93 | + K --> P[exec_parent] |
| 94 | + B --> Q[free_command_group] |
| 95 | + A --> R[return exit_status] |
| 96 | + I --> S[exec_cmd] |
| 97 | + N --> S |
| 98 | + S --> T[set_filedirectories] |
| 99 | + T --> U[handle_append_output] |
| 100 | + T --> V[handle_heredoc] |
| 101 | + T --> W[handle_overwrite_output] |
| 102 | + T --> X[handle_input_redir] |
| 103 | + S --> Y[save_fds] |
| 104 | + S --> Z[apply_redirections] |
| 105 | + S --> AA[process_command] |
| 106 | + AA --> AB{is builtin?} |
| 107 | + AB -->|Yes| AC[process_builtin] |
| 108 | + AB -->|No| AD[exec_non_builtin] |
| 109 | + AC --> AE[exec_cmd_builtin] |
| 110 | + AD --> AF[handle_cmd_with_path] |
| 111 | + AD --> AG[handle_cmd_without_path] |
| 112 | + AF --> AH[check_executable_access] |
| 113 | + AG --> AI[find_executable_in_path] |
| 114 | + AI --> AJ[search_executable_in_paths] |
| 115 | + AD --> AK[exec_cmd_external] |
| 116 | + AK --> AL[ft_execvp] |
| 117 | + AL --> AM[try_execve_in_paths] |
| 118 | + AL --> AN[execve] |
| 119 | + AK --> AO[perror] |
| 120 | + AE --> AP[shell_echo] |
| 121 | + AE --> AQ[shell_cd] |
| 122 | + AE --> AR[shell_exit] |
| 123 | + AE --> AS[shell_pwd] |
| 124 | + AE --> AT[shell_export] |
| 125 | + AE --> AU[shell_unset] |
| 126 | + AE --> AV[shell_env] |
| 127 | + V --> AW[execute_heredoc] |
| 128 | + AW --> AX[heredoc_loop] |
| 129 | + U --> AY[open] |
| 130 | + W --> AZ[open] |
| 131 | + X --> BA[open] |
| 132 | + Z --> BB[dup2] |
| 133 | + Y --> BC[dup] |
| 134 | + BB --> BD[close] |
| 135 | + BC --> BE[close] |
| 136 | + J --> BF[waitpid] |
| 137 | + O --> BG[close] |
| 138 | + L --> BH[pipe] |
| 139 | + BH --> BI[perror] |
| 140 | + BI --> BJ[exit] |
| 141 | +
|
| 142 | + subgraph "Initialization and Execution" |
| 143 | + A[exec_ast] |
| 144 | + B[exec_command_group] |
| 145 | + C{is no command?} |
| 146 | + D[return 0] |
| 147 | + E{is single command?} |
| 148 | + F{is exit/cd/unset/export?} |
| 149 | + G[exec_cmd_builtin] |
| 150 | + H[fork] |
| 151 | + I[exec_child_process] |
| 152 | + J[exec_parent] |
| 153 | + Q[free_command_group] |
| 154 | + R[return exit_status] |
| 155 | + end |
| 156 | +
|
| 157 | + subgraph "Command Execution" |
| 158 | + K[process_command] |
| 159 | + L[setup_pipe_and_fork] |
| 160 | + M[fork] |
| 161 | + N[execute_child] |
| 162 | + O[setup_parent_pipe] |
| 163 | + P[exec_parent] |
| 164 | + S[exec_cmd] |
| 165 | + T[set_filedirectories] |
| 166 | + U[handle_append_output] |
| 167 | + V[handle_heredoc] |
| 168 | + W[handle_overwrite_output] |
| 169 | + X[handle_input_redir] |
| 170 | + Y[save_fds] |
| 171 | + Z[apply_redirections] |
| 172 | + AA[process_command] |
| 173 | + AB{is builtin?} |
| 174 | + AC[process_builtin] |
| 175 | + AD[exec_non_builtin] |
| 176 | + AE[exec_cmd_builtin] |
| 177 | + AF[handle_cmd_with_path] |
| 178 | + AG[handle_cmd_without_path] |
| 179 | + AH[check_executable_access] |
| 180 | + AI[find_executable_in_path] |
| 181 | + AJ[search_executable_in_paths] |
| 182 | + AK[exec_cmd_external] |
| 183 | + AL[ft_execvp] |
| 184 | + AM[try_execve_in_paths] |
| 185 | + AN[execve] |
| 186 | + AO[perror] |
| 187 | + AP[shell_echo] |
| 188 | + AQ[shell_cd] |
| 189 | + AR[shell_exit] |
| 190 | + AS[shell_pwd] |
| 191 | + AT[shell_export] |
| 192 | + AU[shell_unset] |
| 193 | + AV[shell_env] |
| 194 | + AW[execute_heredoc] |
| 195 | + AX[heredoc_loop] |
| 196 | + AY[open] |
| 197 | + AZ[open] |
| 198 | + BA[open] |
| 199 | + BB[dup2] |
| 200 | + BC[dup] |
| 201 | + BD[close] |
| 202 | + BE[close] |
| 203 | + BF[waitpid] |
| 204 | + BG[close] |
| 205 | + BH[pipe] |
| 206 | + BI[perror] |
| 207 | + BJ[exit] |
| 208 | + end |
| 209 | +
|
| 210 | +
|
| 211 | +
|
| 212 | +``` |
| 213 | + |
| 214 | +## Installation |
| 215 | +1. **Clone the repository:** |
| 216 | + ```bash |
| 217 | + git clone https://github.com/yourusername/minishell.git |
| 218 | + ``` |
| 219 | +2. **Navigate to the project directory:** |
| 220 | + ```bash |
| 221 | + cd minishell |
| 222 | + ``` |
| 223 | +3. Compile the project: |
| 224 | + ```bash |
| 225 | + make |
| 226 | + ``` |
| 227 | + |
| 228 | +## Usage |
| 229 | +- Start the Shell: |
| 230 | + ```bash |
| 231 | + ./minishell |
| 232 | + ``` |
| 233 | +- Enter commands at the prompt. |
| 234 | +- Exit by typing exit or pressing Ctrl-D. |
2 | 235 |
|
3 |
| -docker build -t minishell . |
4 | 236 |
|
5 |
| -docker run -it --rm -v "$(pwd)":/app -w /app minishell /bin/bash |
|
0 commit comments