{"id":19079432,"url":"https://github.com/hackersa3edy/simple_shell","last_synced_at":"2026-05-14T01:39:39.112Z","repository":{"id":209950118,"uuid":"704144839","full_name":"hackerSa3edy/simple_shell","owner":"hackerSa3edy","description":"ALX Sprint 1 project - Simple Shell: The shell is a program that takes the command inputs written from the the user’s keyboard and passes them to the machine to execute them through the kernel. It also verifies if the command inputs from the user are correct. So, in general, a shell is a user interface to use the services of a computer.","archived":false,"fork":false,"pushed_at":"2024-10-21T15:19:53.000Z","size":456,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-22T05:28:35.089Z","etag":null,"topics":["algorithms","alx","alx-software-engineering","c-language","c-programming","cli","command-line","data-structures","debugging","kernel","optimization","shell","system-calls","valgrind"],"latest_commit_sha":null,"homepage":"","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/hackerSa3edy.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":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-12T16:18:30.000Z","updated_at":"2024-10-21T15:19:57.000Z","dependencies_parsed_at":"2024-10-22T15:07:26.619Z","dependency_job_id":null,"html_url":"https://github.com/hackerSa3edy/simple_shell","commit_stats":null,"previous_names":["hackersa3edy/simple_shell"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hackerSa3edy/simple_shell","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerSa3edy%2Fsimple_shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerSa3edy%2Fsimple_shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerSa3edy%2Fsimple_shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerSa3edy%2Fsimple_shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackerSa3edy","download_url":"https://codeload.github.com/hackerSa3edy/simple_shell/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackerSa3edy%2Fsimple_shell/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33006716,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"ssl_error","status_checked_at":"2026-05-13T13:14:51.610Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["algorithms","alx","alx-software-engineering","c-language","c-programming","cli","command-line","data-structures","debugging","kernel","optimization","shell","system-calls","valgrind"],"created_at":"2024-11-09T02:14:40.440Z","updated_at":"2026-05-14T01:39:39.078Z","avatar_url":"https://github.com/hackerSa3edy.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Project: 0x16. C - Simple Shell\n\n![Gates of Shell](./media/shell.jpeg)\n\nA simple UNIX command language interpreter that reads commands from either a file or standard input and executes them.\n\n## Table of Contents\n\n1. [What is a shell?](#what-is-a-shell)\n2. [How the shell works](#how-the-shell-works)\n3. [Description](#description)\n4. [Features](#features)\n5. [Installation](#installation)\n6. [Usage](#usage)\n7. [Built-in Commands](#built-in-commands)\n8. [Environment](#environment)\n9. [Exit Status](#exit-status)\n10. [Signals](#signals)\n11. [Command Execution](#command-execution)\n12. [Operators](#operators)\n13. [Examples](#examples)\n14. [Troubleshooting](#troubleshooting)\n15. [Contact](#authors)\n\n## What is a shell?\n\nA shell is a program that takes the command inputs written from the the user’s keyboard and passes them to the machine to execute them through the kernel. It also verifies if the command inputs from the user are correct.\n\n![A shell is a messanger between the user, the kernel and the machine.](./media/cli-flow.webp)\n\nSo, in general, a Shell is a user interface to use the services of a computer.\n\n## How the shell works\n\nThe shell follows a simple cycle:\n\n1. **R**ead: Accept input from the user\n2. **E**valuate: Interpret the command\n3. **P**rint: Display the output\n4. **L**oop: Return to step 1\n\n![how the shell works](./media/working_shell.png)\n\n### How hsh works\n\n- Prints a prompt and waits for a command from the user.\n- Creates a child process in which the command is checked.\n- Checks for built-ins, aliases in the PATH, and local executable programs.\n- The child process is replaced by the command, which accepts arguments.\n- When the command is done, the program returns to the parent process and prints the prompt.\n- The program is ready to receive a new command\n- To exit: press Ctrl-D or enter \"exit\" (with or without a status).\n- Works also in non interactive mode.\n\n## Description\n\n**hsh** is a simple UNIX command language interpreter developed as part of the ALX Software Engineering program. It mimics the basic functionality of the Bash shell, providing a command-line interface for users to interact with their system.\n\n## Features\n\n- Executes commands from files or standard input\n- Supports built-in commands like `cd`, `exit`, `env`, `setenv`, and `unsetenv`\n- Handles command separators (`;`) and logical operators (`\u0026\u0026`, `||`)\n- Manages environment variables\n- Supports comments (lines starting with `#`)\n- Works in both interactive and non-interactive modes\n\n## Installation\n\n### Prerequisites\n\n- GCC compiler\n- Linux environment (Ubuntu 20.04 LTS recommended)\n\n### Steps\n\n1. Clone the repository:\n\n    ```bash\n    git clone https://github.com/hackerSa3edy/simple_shell.git\n    ```\n\n2. Navigate to the project directory:\n\n    ```bash\n    cd simple_shell\n    ```\n\n3. Compile the program:\n\n    ```bash\n    gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh\n    ```\n\n## Usage\n\n### Interactive Mode\n\nRun the shell:\n\n```bash\n./hsh\n```\n\nYou will see a prompt where you can type commands:\n\n```bash\nls -l\npwd\necho Hello, World!\n```\n\n### Non-Interactive Mode\n\nExecute commands from a file:\n\n```bash\n./hsh \u003c commands.txt\n```\n\nOr pipe commands to the shell:\n\n```bash\necho \"ls -l\" | ./hsh\n```\n\n## Built-in Commands\n\n- `cd [DIRECTORY]`: Change the current directory\n- `exit [STATUS]`: Exit the shell with a given status\n- `env`: Print the current environment\n- `setenv [VARIABLE] [VALUE]`: Set an environment variable\n- `unsetenv [VARIABLE]`: Unset an environment variable\n\n## Environment\n\nThe shell uses the following environment variables:\n\n- `HOME`: The home directory of the current user\n- `PWD`: The current working directory\n- `OLDPWD`: The previous working directory\n- `PATH`: A colon-separated list of directories to search for commands\n\n## Exit Status\n\n**hsh** returns the exit status of the last command executed, with zero indicating success and non-zero indicating failure.\n\nIf a command is not found, the return status is `127`; if a command is found but is not executable, the return status is 126.\n\nAll builtins return zero on success and one or two on incorrect usage (indicated by a corresponding error message).\n\n## Signals\n\nWhile running in interactive mode, **hsh** ignores the keyboard input `Ctrl+c`. Alternatively, an input of end-of-file (`Ctrl+d`) will exit the program.\n\nUser hits `Ctrl+d` in the third line.\n\n```bash\n./hsh\n^C\n^C\n\n```\n\n## Command Execution\n\nUpon receiving a command, **hsh** tokenizes it into words using spaces as delimiters. The first word is interpreted as the command, while all subsequent words are treated as arguments. **hsh** then proceeds with the following steps:\n\n1. If the command doesn't begin with a slash (`/`) or dot (`.`), the shell first checks its list of built-in functions. If a matching built-in is found, it is executed.\n\n2. If the command doesn't start with a slash (`/`), dot (`.`), and isn't a built-in function, **hsh** searches for an executable file with the command name in each directory listed in the **PATH** environment variable.\n\n3. If the command begins with a slash (`/`) or dot (`.`), or if either of the above searches succeeds, the shell executes the specified program with any provided arguments in a separate execution environment.\n\n## Operators\n\n- `;`: Command separator\n- `\u0026\u0026`: AND logical operator\n- `||`: OR logical operator\n\n## Examples\n\n### Using command separator\n\n```bash\necho Hello ; ls\n```\n\n```bash\n# Output\nHello\nfile1 file2 file3\n```\n\n### Using AND operator\n\n```bash\nmkdir test \u0026\u0026 cd test \u0026\u0026 pwd\n```\n\n```bash\n# Output\n/home/user/test\n```\n\n### Using OR operator\n\n```bash\nls /nonexistent || echo \"Directory not found\"\n```\n\n```bash\n# Output\nDirectory not found\n```\n\n## Troubleshooting\n\n- **Command not found**: Ensure the command exists and is in your PATH\n- **Permission denied**: Check if you have the necessary permissions to execute the file\n- **Syntax errors**: Verify your command syntax, especially when using operators\n\n## Authors\n\n- [Abdelrahman Mohamed](https://x.com/hackersa3edy)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackersa3edy%2Fsimple_shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackersa3edy%2Fsimple_shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackersa3edy%2Fsimple_shell/lists"}