{"id":18429284,"url":"https://github.com/symonmuchemi/shell_emulator","last_synced_at":"2026-04-28T18:31:13.430Z","repository":{"id":182264771,"uuid":"667970633","full_name":"SymonMuchemi/Shell_emulator","owner":"SymonMuchemi","description":"Shell emulator ","archived":false,"fork":false,"pushed_at":"2023-07-29T14:42:54.000Z","size":80,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-16T08:42:52.781Z","etag":null,"topics":["c-programming","shell"],"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/SymonMuchemi.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-07-18T18:01:33.000Z","updated_at":"2023-08-02T21:11:43.000Z","dependencies_parsed_at":"2024-11-06T05:16:28.921Z","dependency_job_id":"0ff13b01-cfae-4f78-abe5-dc09d0490203","html_url":"https://github.com/SymonMuchemi/Shell_emulator","commit_stats":null,"previous_names":["symonmuchemi/simple_shell","symonmuchemi/shell_emulator"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymonMuchemi%2FShell_emulator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymonMuchemi%2FShell_emulator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymonMuchemi%2FShell_emulator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SymonMuchemi%2FShell_emulator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SymonMuchemi","download_url":"https://codeload.github.com/SymonMuchemi/Shell_emulator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248788867,"owners_count":21161726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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-programming","shell"],"created_at":"2024-11-06T05:16:31.967Z","updated_at":"2026-04-28T18:31:13.390Z","avatar_url":"https://github.com/SymonMuchemi.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 0x16. C - Simple Shell\n\n## More Info\n### Output\n\n- Unless specified otherwise, your program *must have the exact same output* as sh (`/bin/sh`) as well as the exact same error output.\n- The only difference is when you print an error, the name of the program must be equivalent to your `argv[0]` (See below)\n\nExample of error with `sh`:\n```shell\n$ echo \"qwerty\" | /bin/sh\n/bin/sh: 1: qwerty: not found\n$ echo \"qwerty\" | /bin/../bin/sh\n/bin/../bin/sh: 1: qwerty: not found\n$\n```\nSome error with your program\n```shell\n$ echo \"qwerty\" | ./hsh\n./hsh: 1: qwerty: not found\n$ echo \"qwerty\" | ./././hsh\n./././hsh: 1: qwerty: not found\n$\n```\n## List of allowed functions\n- `access` (man 2 access)\n- `chdir` (man 2 chdir)\n- `close` (man 2 close)\n- `closedir` (man 3 closedir)\n- `execve` (man 2 execve)\n- `exit` (man 3 exit)\n- `_exit` (man 2 _exit)\n- `fflush` (man 3 fflush)\n- `fork` (man 2 fork)\n- `free` (man 3 free)\n- `getcwd` (man 3 getcwd)\n- `getline` (man 3 getline)\n- `getpid` (man 2 getpid)\n- `isatty` (man 3 isatty)\n- `kill` (man 2 kill)\n- `malloc` (man 3 malloc)\n- `open` (man 2 open)\n- `opendir` (man 3 opendir)\n- `perror `(man 3 perror)\n- `read` (man 2 read)\n- `readdir` (man 3 readdir)\n- `signal` (man 2 signal)\n- `stat` (__xstat) (man 2 stat)\n- `lstat` (__lxstat) (man 2 lstat)\n- `fstat` (__fxstat) (man 2 fstat)\n- `strtok` (man 3 strtok)\n- `wait` (man 2 wait)\n- `waitpid` (man 2 waitpid)\n- `wait3` (man 2 wait3)\n- `wait4` (man 2 wait4)\n- `write` (man 2 write)\n****\n### Compilation\nYour shel will be compiled this way:\n\n```shell\ngcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh\n```\n### Testing\n\nYour shell should work like this in interactive mode:\n\n```shell\n$ ./hsh\n($) /bin/ls\nhsh main.c shell.c\n($)\n($) exit\n$```\n\nBut also in non-interactive mode:\n\n```shell\n$ echo \"/bin/ls\" | ./hsh\nhsh main.c shell.c test_ls_2\n$\n$ cat test_ls_2\n/bin/ls\n/bin/ls\n$\n$ cat test_ls_2 | ./hsh\nhsh main.c shell.c test_ls_2\nhsh main.c shell.c test_ls_2\n$\n```\n\n### Checks\n\nThe Checker will be released at the end of the project (1-2 days before the deadline). We strongly encourage the entire class to work together to create a suite of checks covering both regular tests and edge cases for each task. See task `8. Test suite`.\n\n## Tasks\n### 0. Betty would be proud\nWrite a beautiful code that passes the Betty checks\n\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 1. Simple shell 0.1\n\nWrite a UNIX command line interpreter.\n\n- Usage: `simple_shell`\nYour Shell should:\n\n    - Display a prompt and wait for the user to type a command. A command line always ends with a new line.\n    - The prompt is displayed again each time a command has been executed.\n    - The command lines are simple, no semicolons, no pipes, no redirections or any other advanced features.\n    - The command lines are made only of one word. No arguments will be passed to programs.\n    - If an executable cannot be found, print an error message and display the prompt again.\n    - Handle errors.\n    - You have to handle the “end of file” condition (`Ctrl+D`)\nYou don’t have to:\n\n    - use the `PATH`\n    - implement built-ins\n    - handle special characters : `\"`,  `'`, `,` \\`, `*`, `\u0026`, `#`\n    - be able to move the cursor\n    - handle commands with arguments\n\n`execve` will be the core part of your Shell, don’t forget to pass the environ to it…\n\n```shell\n\njulien@ubuntu:~/shell$ ./shell \n#cisfun$ ls\n./shell: No such file or directory\n#cisfun$ /bin/ls\nbarbie_j       env-main.c  exec.c  fork.c  pid.c  ppid.c    prompt   prompt.c  shell.c  stat.c         wait\nenv-environ.c  exec    fork    mypid   ppid   printenv  promptc  shell     stat test_scripting.sh  wait.c\n#cisfun$ /bin/ls -l\n./shell: No such file or directory\n#cisfun$ ^[[D^[[D^[[D\n./shell: No such file or directory\n#cisfun$ ^[[C^[[C^[[C^[[C\n./shell: No such file or directory\n#cisfun$ exit\n./shell: No such file or directory\n#cisfun$ ^C\njulien@ubuntu:~/shell$ echo \"/bin/ls\" | ./shell\nbarbie_j       env-main.c  exec.c  fork.c  pid.c  ppid.c    prompt   prompt.c  shell.c  stat.c         wait\nenv-environ.c  exec    fork    mypid   ppid   printenv  promptc  shell     stat test_scripting.sh  wait.c\n#cisfun$ julien@ubuntu:~/shell$\n\n```\n*Repo:*\n\n- GitHub repository: `simple_shell`\n  \n### 2. Simple shell 0.2\n\nSimple shell 0.1 +\n\n- Handle command lines with arguments\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 3. Simple shell 0.3\n\nSimple shell 0.2 +\n\n- Handle the `PATH`\n- `fork` must not be called if the command doesn’t exist\n```shell\njulien@ubuntu:~/shell$ ./shell_0.3\n:) /bin/ls\nbarbie_j       env-main.c  exec.c  fork.c  pid.c  ppid.c    prompt   prompt.c  shell_0.3  stat    test_scripting.sh  wait.c\nenv-environ.c  exec    fork    mypid   ppid   printenv  promptc  shell     shell.c    stat.c  wait\n:) ls\nbarbie_j       env-main.c  exec.c  fork.c  pid.c  ppid.c    prompt   prompt.c  shell_0.3  stat    test_scripting.sh  wait.c\nenv-environ.c  exec    fork    mypid   ppid   printenv  promptc  shell     shell.c    stat.c  wait\n:) ls -l /tmp \ntotal 20\n-rw------- 1 julien julien    0 Dec  5 12:09 config-err-aAMZrR\ndrwx------ 3 root   root   4096 Dec  5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-colord.service-V7DUzr\ndrwx------ 3 root   root   4096 Dec  5 12:09 systemd-private-062a0eca7f2a44349733e78cb4abdff4-rtkit-daemon.service-ANGvoV\ndrwx------ 3 root   root   4096 Dec  5 12:07 systemd-private-062a0eca7f2a44349733e78cb4abdff4-systemd-timesyncd.service-CdXUtH\n-rw-rw-r-- 1 julien julien    0 Dec  5 12:09 unity_support_test.0\n:) ^C\njulien@ubuntu:~/shell$ \n\n```\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 4. Simple shell 0.4\n\nSimple shell 0.3 +\n\n- Implement the `exit` built-in, that exits the shell\n- Usage: `exit`\n- You don’t have to handle any argument to the built-in `exit`\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 5. Simple shell 1.0\nSimple shell 0.4 +\n\n- Implement the `env` *built-in*, that prints the current environment\n\n```shell\njulien@ubuntu:~/shell$ ./simple_shell\n$ env\nUSER=julien\nLANGUAGE=en_US\nSESSION=ubuntu\nCOMPIZ_CONFIG_PROFILE=ubuntu\nSHLVL=1\nHOME=/home/julien\nC_IS=Fun_:)\nDESKTOP_SESSION=ubuntu\nLOGNAME=julien\nTERM=xterm-256color\nPATH=/home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\nDISPLAY=:0\n$ exit\njulien@ubuntu:~/shell$ \n```\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 6. Simple shell 0.1.1\nSimple shell 0.1 +\n\n- Write your own `getline` function\n- Use a buffer to read many chars at once and call the least possible the `read` system call\n- You will need to use `static` variables\n- You are not allowed to use `getline`\n\nYou don’t have to:\n\n- be able to move the cursor\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 7. Simple shell 0.2.1\n\nSimple shell 0.2 +\n\nYou are not allowed to use `strtok`\n*Repo:*\n\n- GitHub repository: `simple_shell`\n### 8. Simple shell 0.4.1\nSimple shell 0.4 +\n\n- handle arguments for the built-in `exit`\n- Usage: `exit status`, where status is an integer used to `exit` the shell\n\n```shell\njulien@ubuntu:~/shell$ ./shell_0.4.1\n$ exit 98\njulien@ubuntu:~/shell$ echo $?\n98\njulien@ubuntu:~/shell$ \n```\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 9. setenv, unsetenv\nSimple shell 1.0 +\n\nImplement the `setenv` and `unsetenv` builtin commands\n\n-`setenv`\n    - Initialize a new environment variable, or modify an existing one\n    - Command syntax: `setenv VARIABLE VALUE`\n    - Should print something on stderr on failure\n- `unsetenv`\n    - Remove an environment variable\n    - Command syntax: unsetenv VARIABLE\n    - Should print something on stderr on failure\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 10. cd\n\nSimple shell 1.0 +\n\nImplement the builtin command `cd`:\n\n- Changes the current directory of the process.\n- Command syntax: `cd [DIRECTORY]`\n- If no argument is given to cd the command must be interpreted like `cd $HOME`\n- You have to handle the command `cd -`\n- You have to update the environment variable `PWD` when you change directory\n`man chdir`, `man getcwd`\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 11. ;\n\nSimple shell 1.0 +\n\n- Handle the commands separator `;`\n```shell\nalex@~$ ls /var ; ls /var\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$ ls /hbtn ; ls /var\nls: cannot access /hbtn: No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$ ls /var ; ls /hbtn\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nls: cannot access /hbtn: No such file or directory\nalex@~$ ls /var ; ls /hbtn ; ls /var ; ls /var\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nls: cannot access /hbtn: No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$\n```\n*Repo:*\n\n- GitHub repository: `simple_shell`\n### 12. \u0026\u0026 and ||\nSimple shell 1.0 +\n\n- Handle the `\u0026\u0026` and `||` shell logical operators\n```shell\nalex@~$ ls /var \u0026\u0026 ls /var\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$ ls /hbtn \u0026\u0026 ls /var\nls: cannot access /hbtn: No such file or directory\nalex@~$ ls /var \u0026\u0026 ls /var \u0026\u0026 ls /var \u0026\u0026 ls /hbtn\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nls: cannot access /hbtn: No such file or directory\nalex@~$ ls /var \u0026\u0026 ls /var \u0026\u0026 ls /var \u0026\u0026 ls /hbtn \u0026\u0026 ls /hbtn\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nls: cannot access /hbtn: No such file or directory\nalex@~$\nalex@~$ ls /var || ls /var\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$ ls /hbtn || ls /var\nls: cannot access /hbtn: No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var\nls: cannot access /hbtn: No such file or directory\nls: cannot access /hbtn: No such file or directory\nls: cannot access /hbtn: No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$ ls /hbtn || ls /hbtn || ls /hbtn || ls /var || ls /var\nls: cannot access /hbtn: No such file or directory\nls: cannot access /hbtn: No such file or directory\nls: cannot access /hbtn: No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  spool  tmp\nalex@~$\n```\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 13. alias\nSimple shell 1.0 +\n\nImplement the `alias` builtin command\nUsage: `alias [name[='value'] ...]`\n    - `alias`: Prints a list of all aliases, one per line, in the form `name='value'`\n    - `alias name [name2 ...]`: Prints the aliases `name`, `name2`, etc 1 per line, in the form `name='value'`\n    -alias `name='value' [...]`: Defines an alias for each `name` whose `value` is given. If `name` is already an alias, replaces its value with `value`\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 14. Variables\nSimple shell 1.0 +\n\n- Handle variables replacement\n- Handle the `$?` variable\n- Handle the `$$` variable\n```shell\n\njulien@ubuntu:~/shell$ ./hsh\n$ ls /var\nbackups  cache  crash  lib  local  lock  log  mail  metrics  opt  run  snap  spool  tmp\n$ echo $?\n0\n$ echo $$\n5104\n$ echo $PATH\n/home/julien/bin:/home/julien/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\n$ exit \njulien@ubuntu:~/shell$ \n```\n\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 15. Comments\nSimple shell 1.0 +\n\nHandle comments (`#`)\n```shell\njulien@ubuntu:~/shell$ sh\n$ echo $$ # ls -la\n5114\n$ exit\njulien@ubuntu:~/shell$ \n```\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n### 16. File as input\nSimple shell 1.0 +\n\n- Usage: `simple_shell [filename]`\n- Your shell can take a file as a command line argument\n- The file contains all the commands that your shell should run before exiting\n- The file should contain one command per line\n- In this mode, the shell should not print a prompt and should not read from `stdin`\n*Repo:*\n\n- GitHub repository: `simple_shell`\n\n****\n## # USAGE\nYou can try our shell by following these steps:\n\u003e **Step 1:** Clone our repository using this command, (you need to have git installed on your machine first)\n````\ngit clone https://github.com/MatriMariem/simple_shell\n````\n\u003e **Step 2:** Change directory to simple_shell:\n````\ncd simple_shell\n````\n\u003e **Step 3:** Compile the C files in this way:\n````\ngcc -Wall -Werror -Wextra -pedantic *.c -o hsh\n````\n\u003e **Step 4:** Run the shell\n````\n./hsh\n````\n**Exiting the shell**\nWhen you want to exit the shell, you can use one of the following methods:\n\u003e **1: Type the command \"exit\"**\n````\nexit\n````\n\u003e **2: Press on Ctrl + D**\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymonmuchemi%2Fshell_emulator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsymonmuchemi%2Fshell_emulator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsymonmuchemi%2Fshell_emulator/lists"}