{"id":23401054,"url":"https://github.com/shoaib1522/unix-shell-creation","last_synced_at":"2026-04-26T12:31:28.744Z","repository":{"id":259274457,"uuid":"876338260","full_name":"shoaib1522/UNIX-Shell-Creation","owner":"shoaib1522","description":"A Unix shell is a command-line interpreter that provides a user interface for interacting with Unix-like operating systems. It acts as a bridge between the user and the kernel, allowing you to execute commands, manipulate files, and automate tasks.","archived":false,"fork":false,"pushed_at":"2024-11-03T16:12:42.000Z","size":480,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-08T20:48:53.604Z","etag":null,"topics":["c","config","history-management","operating-system","programming","shell-script","shellscript","unix-shell","version-control"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shoaib1522.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2024-10-21T19:53:50.000Z","updated_at":"2024-12-11T16:25:20.000Z","dependencies_parsed_at":"2024-10-24T02:41:38.576Z","dependency_job_id":"81156dec-f974-4b4a-9b94-733d3492d7df","html_url":"https://github.com/shoaib1522/UNIX-Shell-Creation","commit_stats":null,"previous_names":["shoaib1522/unix-shell-creation"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/shoaib1522/UNIX-Shell-Creation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoaib1522%2FUNIX-Shell-Creation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoaib1522%2FUNIX-Shell-Creation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoaib1522%2FUNIX-Shell-Creation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoaib1522%2FUNIX-Shell-Creation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shoaib1522","download_url":"https://codeload.github.com/shoaib1522/UNIX-Shell-Creation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shoaib1522%2FUNIX-Shell-Creation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32297893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T09:34:17.070Z","status":"ssl_error","status_checked_at":"2026-04-26T09:34:00.993Z","response_time":129,"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":["c","config","history-management","operating-system","programming","shell-script","shellscript","unix-shell","version-control"],"created_at":"2024-12-22T11:14:14.819Z","updated_at":"2026-04-26T12:31:28.725Z","avatar_url":"https://github.com/shoaib1522.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n# UNIX Shell Project\n\n## Overview\nThis project involves creating a custom UNIX shell for an Operating Systems lab assignment. The shell simulates essential shell features, allowing users to execute commands, manage background processes, use input/output redirection, manage command history, and handle shell variables. Each version of the shell builds upon the previous, gradually adding more functionality until a fully functional shell environment is achieved.\n\n## Features by Version\n\n### Version 01: Basic Shell\n- **Objective**: Implement the foundational shell capabilities.\n- **Features**:\n  - Displays a custom prompt.\n  - Parses user input to execute basic commands.\n  - Uses `fork()` and `exec()` to execute commands in a child process.\n  - Allows the shell to exit using the `exit` command or `\u003cCTRL+D\u003e`.\n  \n- **Usage**:\n  - Run simple commands such as `ls`, `pwd`, `whoami`.\n  - Exit by typing `exit` or pressing `\u003cCTRL+D\u003e`.\n\n### Version 02: I/O Redirection\n- **Objective**: Add input and output redirection.\n- **Features**:\n  - Supports output redirection using `\u003e`.\n  - Supports input redirection using `\u003c`.\n  - Allows combined input and output redirection, e.g., `command \u003c input.txt \u003e output.txt`.\n  \n- **Usage**:\n  - Redirect output: `ls \u003e output.txt` (writes the output of `ls` to `output.txt`).\n  - Redirect input: `sort \u003c unsorted.txt` (reads from `unsorted.txt`).\n  - Combined redirection: `sort \u003c unsorted.txt \u003e sorted.txt` (sorts contents of `unsorted.txt` and writes to `sorted.txt`).\n\n### Version 03: Background Processes\n- **Objective**: Implement background processing.\n- **Features**:\n  - Enables background process execution by appending `\u0026` to commands.\n  - Displays background job details (PID and job ID) when a job is started.\n  - Prevents \"zombie\" processes by handling background processes in a non-blocking way using `waitpid()` with `WNOHANG`.\n  \n- **Usage**:\n  - Start a background job: `sleep 30 \u0026` (runs `sleep` in the background).\n  - List background jobs: `jobs`.\n  - Kill a background job: `kill \u003cpid\u003e` (replace `\u003cpid\u003e` with the process ID).\n\n### Version 04: Command History\n- **Objective**: Provide a command history feature.\n- **Features**:\n  - Tracks up to the last 10 commands.\n  - Displays command history using `history`.\n  - Supports re-execution of a specific command from history by typing `!number`, where `number` is the command’s position in the history list.\n  \n- **Usage**:\n  - View history: `history` (lists the last 10 commands).\n  - Execute a previous command: `!1` (executes the first command from history).\n\n### Version 05: Built-In Commands\n- **Objective**: Implement core built-in commands without forking.\n- **Features**:\n  - Implements essential built-in commands: `cd`, `jobs`, `kill`, and `help`.\n    - `cd \u003cdirectory\u003e`: Changes the current directory.\n    - `jobs`: Lists all active background jobs.\n    - `kill \u003cpid\u003e`: Terminates a background process by its PID.\n    - `help`: Displays available built-in commands and their usage.\n  \n- **Usage**:\n  - Change directory: `cd /tmp` (moves to `/tmp` directory).\n  - View background jobs: `jobs`.\n  - Terminate a process: `kill \u003cpid\u003e`.\n  - Get help: `help`.\n\n### Version 06: Shell Variables\n- **Objective**: Add shell variable support for setting, retrieving, and unsetting variables.\n- **Features**:\n  - Enables users to define variables with `set \u003cname\u003e=\u003cvalue\u003e`.\n  - Retrieves variable values by typing the variable name directly.\n  - Lists all defined shell variables using `printenv`.\n  - Unsets (removes) a variable with `unset \u003cname\u003e`.\n  \n- **Usage**:\n  - Set a variable: `set myvar=hello` (creates a variable `myvar` with the value `hello`).\n  - Access a variable: `myvar` (prints `hello`).\n  - List all variables: `printenv`.\n  - Unset a variable: `unset myvar` (removes `myvar`).\n\n## How to Run the Project\n1. **Compile the Code**:\n   - Open a terminal in the directory containing your code file (e.g., `shell.c`).\n   - Compile the shell with:\n     ```bash\n     gcc -o myshell shell.c\n     ```\n\n2. **Run the Shell**:\n   - Start the shell by running:\n     ```bash\n     ./myshell\n     ```\n\n## Testing Each Version\n\n### Version 01: Basic Shell\n1. Run commands such as `ls`, `pwd`, and `whoami` to confirm basic execution.\n2. Type `exit` or press `\u003cCTRL+D\u003e` to exit the shell.\n\n### Version 02: I/O Redirection\n1. Output redirection: `ls \u003e output.txt`. Check `output.txt` for output.\n2. Input redirection: Create `unsorted.txt`, then run `sort \u003c unsorted.txt`.\n3. Combined redirection: `sort \u003c unsorted.txt \u003e sorted.txt`. Check `sorted.txt`.\n\n### Version 03: Background Processes\n1. Start a background job: `sleep 30 \u0026`.\n2. View active jobs with `jobs`.\n3. Kill a job using `kill \u003cpid\u003e`, where `\u003cpid\u003e` is from `jobs`.\n\n### Version 04: Command History\n1. Run several commands (`ls`, `pwd`, `whoami`).\n2. Type `history` to view the last 10 commands.\n3. Use `!number` (e.g., `!1`) to repeat a command from history.\n\n### Version 05: Built-In Commands\n1. `cd /tmp` to test changing directories.\n2. Start a background job (`sleep 30 \u0026`), then check with `jobs`.\n3. Terminate a job with `kill \u003cpid\u003e` from `jobs`.\n4. Type `help` to view all built-in commands.\n\n### Version 06: Shell Variables\n1. Set a variable: `set myvar=hello`.\n2. Access it by typing `myvar` (should output `hello`).\n3. List all variables with `printenv`.\n4. Unset `myvar` with `unset myvar` and verify it no longer displays.\n\n## Example Usage\nHere’s an example session showing the use of various features across all versions:\n\n```bash\nPUCITshell@/home/user:- ls\nfile1.txt  file2.txt  shell.c\nPUCITshell@/home/user:- set myvar=hello\nPUCITshell@/home/user:- myvar\nhello\nPUCITshell@/home/user:- pwd \u003e output.txt\nPUCITshell@/home/user:- sleep 30 \u0026\n[Background] Started process with PID 1234\nPUCITshell@/home/user:- jobs\n[1] PID: 1234\nPUCITshell@/home/user:- kill 1234\nProcess 1234 terminated.\nPUCITshell@/home/user:- history\n1: ls\n2: set myvar=hello\n3: myvar\n4: pwd \u003e output.txt\n5: sleep 30 \u0026\n6: jobs\nPUCITshell@/home/user:- !1\nfile1.txt  file2.txt  shell.c\nPUCITshell@/home/user:- help\nBuilt-in Commands:\ncd \u003cdirectory\u003e - Change directory\nexit - Exit the shell\njobs - List background jobs\nkill \u003cpid\u003e - Terminate background process with PID\nhistory - Display command history\nset \u003cname\u003e=\u003cvalue\u003e - Set a shell variable\nunset \u003cname\u003e - Remove a shell variable\nprintenv - List shell variables\nhelp - List built-in commands\nPUCITshell@/home/user:- printenv\nmyvar=hello\nPUCITshell@/home/user:- unset myvar\nPUCITshell@/home/user:- myvar\nError executing command: No such file or directory\nPUCITshell@/home/user:- exit\n```\n\n## Known Limitations\n- **Limited History**: Only stores the last 10 commands.\n- **Limited Variables**: Supports a maximum of 50 shell variables.\n- **Background Process Limit**: Only allows 10 concurrent background processes.\n  \n## Summary\nThis project emulates core functionalities of a UNIX shell, building progressively with each version:\n- **Basic command execution**.\n- **I/O redirection**.\n- **Background job control**.\n- **Command history management**.\n- **Built-in commands**.\n- **Shell variable management**.\n\nThrough this project, users gain a deep understanding of process control, input/output management, and command handling in a UNIX-like environment, which are crucial skills for systems programming and operating systems development.\n\n## Acknowledgments\nThanks to the Operating Systems Lab course for providing foundational concepts and guidance, and to online resources on `fork()`, `execvp()`, `dup2()`, and signal handling for aiding the development of this shell.\n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoaib1522%2Funix-shell-creation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshoaib1522%2Funix-shell-creation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshoaib1522%2Funix-shell-creation/lists"}