{"id":51472511,"url":"https://github.com/chgomez04/minishell","last_synced_at":"2026-07-06T19:30:23.929Z","repository":{"id":366351832,"uuid":"1275951579","full_name":"chgomez04/minishell","owner":"chgomez04","description":"Unix shell implementation in C developed at 42 Barcelona, with parsing, pipes, redirections, builtins, signals and environment expansion.","archived":false,"fork":false,"pushed_at":"2026-06-21T11:50:25.000Z","size":1349,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-21T14:17:51.725Z","etag":null,"topics":["42-barcelona","42-school","bash","c","execve","file-descriptors","fork","lexer","linux","makefile","minishell","parser","pipes","readline","redirections","shell","signals","unix"],"latest_commit_sha":null,"homepage":"https://github.com/chgomez04","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chgomez04.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-21T10:58:12.000Z","updated_at":"2026-06-21T11:50:28.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/chgomez04/minishell","commit_stats":null,"previous_names":["chgomez04/minishell"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/chgomez04/minishell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgomez04%2Fminishell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgomez04%2Fminishell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgomez04%2Fminishell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgomez04%2Fminishell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chgomez04","download_url":"https://codeload.github.com/chgomez04/minishell/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chgomez04%2Fminishell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35204409,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-06T02:00:07.184Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["42-barcelona","42-school","bash","c","execve","file-descriptors","fork","lexer","linux","makefile","minishell","parser","pipes","readline","redirections","shell","signals","unix"],"created_at":"2026-07-06T19:30:17.278Z","updated_at":"2026-07-06T19:30:23.904Z","avatar_url":"https://github.com/chgomez04.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"*This project was created as part of the 42 curriculum by tmege and chgomez.*\n\n# minishell\n\n## Overview\n\n`minishell` is a Unix shell implementation written in C.\n\nThe project recreates a focused subset of Bash behavior, including interactive input, lexical analysis, syntax validation, environment expansion, command parsing, process execution, pipes, redirections, built-ins and signal handling.\n\nThe goal of the project is to understand how a shell works internally and how Unix processes, file descriptors, signals and environment variables interact.\n\nBuilt collaboratively by `tmege` and `chgomez`.\n\n## Description\n\n`minishell` reads a command line from the user, analyzes it, expands variables, builds an internal command representation and executes the result.\n\nThe command-processing flow is divided into clear stages:\n\n```text\ninput -\u003e lexer -\u003e syntax checker -\u003e expander -\u003e parser -\u003e executor\n```\n\nThe project focuses on:\n\n- Interactive command-line input.\n- Tokenization and quote-aware parsing.\n- Syntax validation for pipes and redirections.\n- Environment variable expansion.\n- Built-in command implementation.\n- Execution of external commands through `PATH`.\n- Process creation with `fork()`.\n- Program execution with `execve()`.\n- File descriptor redirection with `dup2()`.\n- Pipeline execution with `pipe()`.\n- Signal handling in interactive and child-process contexts.\n- Memory management and cleanup.\n\n## Features\n\n- Interactive prompt using GNU Readline.\n- Command history support.\n- External command execution.\n- `PATH` resolution.\n- Multi-command pipelines.\n- Input redirection with `\u003c`.\n- Output redirection with `\u003e`.\n- Append redirection with `\u003e\u003e`.\n- Heredoc support with `\u003c\u003c`.\n- Single quote handling.\n- Double quote handling.\n- Environment variable expansion with `$VARIABLE`.\n- Previous exit status expansion with `$?`.\n- Built-in command execution.\n- Exit status propagation.\n- Interactive signal handling.\n- Clean resource management.\n\n## Supported Built-ins\n\n| Built-in | Description |\n| --- | --- |\n| `echo` | Prints arguments to standard output |\n| `cd` | Changes the current working directory |\n| `pwd` | Prints the current working directory |\n| `export` | Adds or updates environment variables |\n| `unset` | Removes environment variables |\n| `env` | Prints the current environment |\n| `exit` | Exits the shell |\n\n## Supported Operators\n\n| Operator | Description |\n| --- | --- |\n| `|` | Connects commands through a pipeline |\n| `\u003c` | Redirects input from a file |\n| `\u003e` | Redirects output to a file, truncating it |\n| `\u003e\u003e` | Redirects output to a file, appending to it |\n| `\u003c\u003c` | Starts a heredoc input block |\n\n## Signal Behavior\n\n| Input | Behavior |\n| --- | --- |\n| `Ctrl-C` | Interrupts the current prompt or running child process |\n| `Ctrl-\\` | Managed differently depending on interactive or execution context |\n| `Ctrl-D` | Exits the shell when entered on an empty prompt |\n\nSignal behavior is handled differently depending on whether the shell is waiting for input or executing a child process.\n\n## Technologies\n\n- C language\n- Unix system calls\n- GNU Readline\n- File descriptors\n- Pipes\n- Processes\n- Signals\n- Environment variables\n- Dynamic memory management\n- Makefile\n- Compilation with `cc`\n- Flags: `-Wall -Wextra -Werror`\n\n## Project Structure\n\n```text\n.\n├── Makefile\n├── README.md\n├── es.subject.pdf\n├── Libft/\n├── get_next_line/\n├── inc/\n│   └── minishell.h\n└── src/\n    ├── builtins/\n    ├── executor*.c\n    ├── expander*.c\n    ├── heredoc*.c\n    ├── lexer*.c\n    ├── parser*.c\n    ├── redirections.c\n    ├── signals.c\n    ├── syntax_check.c\n    └── main source files\n```\n\n## Requirements\n\nInstall GNU Readline development files before compiling.\n\nOn Debian or Ubuntu:\n\n```bash\nsudo apt-get install libreadline-dev\n```\n\nYou also need:\n\n- `cc`\n- `make`\n- A Unix-like environment\n\n## How to Compile\n\nCompile the project:\n\n```bash\nmake\n```\n\nThis generates the executable:\n\n```text\nminishell\n```\n\nRemove object files:\n\n```bash\nmake clean\n```\n\nRemove object files and the executable:\n\n```bash\nmake fclean\n```\n\nRebuild the project:\n\n```bash\nmake re\n```\n\n## How to Run\n\nStart the shell:\n\n```bash\n./minishell\n```\n\nExit the shell:\n\n```bash\nexit\n```\n\nor press:\n\n```text\nCtrl-D\n```\n\n## Usage Examples\n\nRun a simple command:\n\n```bash\necho \"Hello, minishell\"\n```\n\nUse an environment variable:\n\n```bash\necho $USER\n```\n\nCheck the previous exit status:\n\n```bash\necho $?\n```\n\nRun a pipeline:\n\n```bash\nls -la | grep \".c\" | wc -l\n```\n\nUse input and output redirection:\n\n```bash\ncat \u003c input.txt \u003e output.txt\n```\n\nAppend output to a file:\n\n```bash\necho \"new line\" \u003e\u003e output.txt\n```\n\nUse a heredoc:\n\n```bash\ncat \u003c\u003c EOF\nhello\nworld\nEOF\n```\n\nUse a quoted heredoc delimiter to avoid expansion:\n\n```bash\ncat \u003c\u003c 'EOF'\n$HOME is kept literal here\nEOF\n```\n\n## Behavior at a Glance\n\n| Area | Supported behavior |\n| --- | --- |\n| Commands | External commands with arguments |\n| Pipelines | Multi-stage pipelines |\n| Redirections | `\u003c`, `\u003e`, `\u003e\u003e`, `\u003c\u003c` |\n| Quoting | Single quotes, double quotes and mixed quoting |\n| Expansion | Environment variables and `$?` |\n| Built-ins | `echo`, `cd`, `pwd`, `export`, `unset`, `env`, `exit` |\n| Signals | Interactive and execution-time signal behavior |\n\n## Testing\n\nRebuild the project:\n\n```bash\nmake re\n```\n\nRun Norminette if available:\n\n```bash\nnorminette inc src Libft get_next_line\n```\n\nRun the shell:\n\n```bash\n./minishell\n```\n\nSuggested manual tests:\n\n```bash\necho hello\necho \"$USER\"\necho '$USER'\npwd\ncd ..\npwd\nexport TEST=minishell\necho $TEST\nunset TEST\nenv\nls -la | grep \".c\" | wc -l\ncat \u003c input.txt | grep minishell \u003e output.txt\necho $?\n```\n\nSuggested syntax-error tests:\n\n```bash\n|\necho \u003e\ncat \u003c\necho hello |\n```\n\nSuggested signal tests:\n\n```bash\nsleep 10\n```\n\nThen press `Ctrl-C`.\n\n## Implementation Highlights\n\n- The lexer converts user input into tokens while respecting quotes.\n- The syntax checker validates pipe and redirection placement before execution.\n- The expander resolves environment variables and `$?`.\n- The parser transforms tokens into executable command structures.\n- The executor handles built-ins, external commands, pipes and process creation.\n- Redirection logic manages input, output, append and heredoc file descriptors.\n- Signal handling is adapted for interactive mode and child-process execution.\n- Environment data is stored and updated internally for built-ins such as `export`, `unset` and `cd`.\n- Cleanup logic releases allocated memory and closes file descriptors across success and error paths.\n\n## What I Learned\n\n- How Unix shells parse and execute commands.\n- How to build a lexer and parser for command-line input.\n- How quoting rules affect tokenization and expansion.\n- How environment variable expansion works.\n- How to implement built-in shell commands.\n- How to create processes with `fork()`.\n- How to execute programs with `execve()`.\n- How to connect commands with `pipe()`.\n- How to redirect input and output with `dup2()`.\n- How to manage signals in interactive programs.\n- How to organize a larger C project with multiple modules.\n- How to work collaboratively on a complex C codebase.\n\n## Resources\n\n- 42 minishell subject\n- Bash Reference Manual\n- POSIX Shell and Utilities documentation\n- GNU Readline documentation\n- Linux manual pages:\n  - `man fork`\n  - `man execve`\n  - `man pipe`\n  - `man dup2`\n  - `man waitpid`\n  - `man signal`\n  - `man readline`\n\n## Notes\n\nThis project follows the constraints and style expected in the 42 curriculum.  \nThe implementation is intentionally written in C and focuses on shell internals, parsing, process management, file descriptors, signals and environment handling.\n\nThis is not intended to be a full Bash replacement. It implements the subset of behavior required by the project subject.\n\n## Authors\n\n`tmege`  \n42 Barcelona student\n\nChristian Gómez (`chgomez`)  \nJunior Software Developer in training at 42 Barcelona  \nGitHub: [github.com/chgomez04](https://github.com/chgomez04)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchgomez04%2Fminishell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchgomez04%2Fminishell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchgomez04%2Fminishell/lists"}