{"id":21458168,"url":"https://github.com/samuelselasi/simple_shell","last_synced_at":"2025-03-17T04:16:21.933Z","repository":{"id":186468499,"uuid":"607249865","full_name":"samuelselasi/simple_shell","owner":"samuelselasi","description":"Custom Linux Shell","archived":false,"fork":false,"pushed_at":"2023-02-27T16:41:29.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T13:43:55.862Z","etag":null,"topics":["bit-manipulation","cprogramming-language","execve","file-input-output","header-files","linux-shell","simple-shell","strtok","struct","typedef"],"latest_commit_sha":null,"homepage":"https://github.com/samuelselasi/simple_shell","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/samuelselasi.png","metadata":{"files":{"readme":"README.md","changelog":"history.c","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}},"created_at":"2023-02-27T16:09:40.000Z","updated_at":"2023-02-27T17:22:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"7e4c09c0-0762-4b76-af29-558baf35071c","html_url":"https://github.com/samuelselasi/simple_shell","commit_stats":null,"previous_names":["samuelselasi/simple_shell"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelselasi%2Fsimple_shell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelselasi%2Fsimple_shell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelselasi%2Fsimple_shell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samuelselasi%2Fsimple_shell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samuelselasi","download_url":"https://codeload.github.com/samuelselasi/simple_shell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243971212,"owners_count":20376784,"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":["bit-manipulation","cprogramming-language","execve","file-input-output","header-files","linux-shell","simple-shell","strtok","struct","typedef"],"created_at":"2024-11-23T06:18:06.211Z","updated_at":"2025-03-17T04:16:21.901Z","avatar_url":"https://github.com/samuelselasi.png","language":"C","readme":"# C Custom Linux Shell\n## Background Context\n* A simple UNIX command interpreter.\n![shell](https://user-images.githubusercontent.com/85158665/219971433-f2b21b08-f3c0-491d-a13b-f925b05660f0.jpeg)\n^ “The Gates of Shell”, by Spencer Cheng, featuring Julien Barbier\n## Requirements\n### General\n* Editors: `vi`, `vim`\n* All files compiled on Ubuntu 20.04 LTS using gcc, using the options `-Wall -Werror -Wextra -pedantic -std=gnu89`\n* All files end with a new line\n* Code uses the `Betty` style. Checked using [betty-style.pl](https://github.com/holbertonschool/Betty/blob/master/betty-style.pl) and [betty-doc.pl](https://github.com/holbertonschool/Betty/blob/master/betty-doc.pl)\n* Shell has no memory leaks\n* No more than 5 functions per file\n* All header files are include guarded: [shell](./shell.h), [error](./error.h), [help](./help.h)\n* System calls used only when needed ([why?](https://www.quora.com/Why-are-system-calls-expensive-in-operating-systems))\n## More Info\n### Output\n* Custom shell has 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 is equivalent to the `argv[0]` (See below)\n## Compilation\n```\ngcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh\n```\n## Testing\nCustom shell works like this in interactive mode:\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ /bin/ls\nAUTHORS    _getline.c  _strcmp.c   _strcpy.c  _strtok.c  built_in.c  error.c    expansions.c  help.h     input.c        memory_func2.c  pow_b.c  shell.h     test_ls_2\nREADME.md  _itoa.c     _strcmpd.c  _strdup.c  _write.c   cd.c        error.h    file_path.c   history.c  linked_lists.c  num_len.c                                                                                                           run.c     sometest    unalias.c\n_atoi.c    _strcat.c   _strcmps.c  _strlen.c  alias.c    env_func.c  execute.c  help.c        hsh        memory_func1.c  parser.c                                                                                                            shell.c  str_func.c\n$ exit\nvagrant@ubuntu-focal:~/simple_shell$\n```\nAnd also in non-interactive mode:\n```\nvagrant@ubuntu-focal:~/simple_shell$ echo \"/bin/ls\" | ./hsh\nAUTHORS    _getline.c  _strcmp.c   _strcpy.c  _strtok.c  built_in.c  error.c    expansions.c  help.h     input.c        memory_func2.c  pow_b.c  shell.h     test_ls_2\nREADME.md  _itoa.c     _strcmpd.c  _strdup.c  _write.c   cd.c        error.h    file_path.c   history.c  linked_lists.c  num_len.c                                                                                                           run.c     sometest    unalias.c\n_atoi.c    _strcat.c   _strcmps.c  _strlen.c  alias.c    env_func.c  execute.c  help.c        hsh        memory_func1.c  parser.c                                                                                                            shell.c  str_func.c\nvagrant@ubuntu-focal:~/simple_shell$\n```\n## Tasks\n```\n0. Code for custom shell complies with [Betty](https://medium.com/@onepunchcoder/writing-clean-effective-code-b29dcfb09ae) conventions.\n```\nCode passes Betty checks.\n* Run `betty *` to verify\n```\n1. Simple shell 0.1\n```\n* UNIX command line interpreter\n* Usage: `simple_shell`\n* The shell:\n* Displays a prompt and waits for the user to type a command.\n* The prompt is displayed again each time a command has been executed.\n* The command line always ends with a new line.\n* If an executable cannot be found, prints an error message and displays the prompt again.\n* Handles the “end of file” condition (`Ctrl+D`)\n*gif here*:\n```\n2. Simple shell 0.2\n```\nSimple shell 0.1 +\n* Handle command lines with arguments\n```\n3. Simple shell 0.3\n```\nSimple shell 0.2 +\n* Handle the `PATH`\n* `fork` must not be called if the command doesn’t exist\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ /bin/ls\nAUTHORS    _getline.c  _strcmp.c   _strcpy.c  _strtok.c  built_in.c  error.c    expansions.c  help.h     input.c        memory_func2.c  pow_b.c  shell.h     test_ls_2\nREADME.md  _itoa.c     _strcmpd.c  _strdup.c  _write.c   cd.c        error.h    file_path.c   history.c  linked_lists.c  num_len.c                                                                                                           run.c     sometest    unalias.c\n_atoi.c    _strcat.c   _strcmps.c  _strlen.c  alias.c    env_func.c  execute.c  help.c        hsh        memory_func1.c  parser.c                                                                                                            shell.c  str_func.c\n$ ls\nAUTHORS    _getline.c  _strcmp.c   _strcpy.c  _strtok.c  built_in.c  error.c    expansions.c  help.h     input.c        memory_func2.c  pow_b.c  shell.h     test_ls_2\nREADME.md  _itoa.c     _strcmpd.c  _strdup.c  _write.c   cd.c        error.h    file_path.c   history.c  linked_lists.c  num_len.c                                                                                                           run.c     sometest    unalias.c\n_atoi.c    _strcat.c   _strcmps.c  _strlen.c  alias.c    env_func.c  execute.c  help.c        hsh        memory_func1.c  parser.c                                                                                                            shell.c  str_func.c\n$ ls -l /tmp\ntotal 20\ndrwx------ 3 root root 4096 Feb 21 06:57 snap-private-tmp\ndrwx------ 3 root root 4096 Feb 21 06:57 systemd-private-66e4732a88ba4d62b85b74050f0d0ead-ModemManager.service-8vrZtj\ndrwx------ 3 root root 4096 Feb 21 06:57 systemd-private-66e4732a88ba4d62b85b74050f0d0ead-systemd-logind.service-09pvYi\ndrwx------ 3 root root 4096 Feb 21 06:57 systemd-private-66e4732a88ba4d62b85b74050f0d0ead-systemd-resolved.service-iInQXh\ndrwx------ 3 root root 4096 Feb 21 06:57 systemd-private-66e4732a88ba4d62b85b74050f0d0ead-systemd-timesyncd.service-a6bQAf\n$ ^C\n$\nvagrant@ubuntu-focal:~/simple_shell$\n```\n```\n4. Simple shell 0.4\n```\nSimple shell 0.3 +\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```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ exit\nvagrant@ubuntu-focal:~/simple_shell$\n```\n```\n5. Simple shell 1.0\n```\nSimple shell 0.4 +\n* Implement the `env` built-in, that prints the current environment\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ env\nSHELL=/bin/bash\nPWD=/home/vagrant/simple_shell\nLOGNAME=vagrant\nXDG_SESSION_TYPE=tty\nMOTD_SHOWN=pam\nHOME=/home/vagrant\nLANG=C.UTF-8\nLS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:\nSSH_CONNECTION=10.0.2.2 56291 10.0.2.15 22\nLESSCLOSE=/usr/bin/lesspipe %s %s\nXDG_SESSION_CLASS=user\nTERM=xterm-256color\nLESSOPEN=| /usr/bin/lesspipe %s\nUSER=vagrant\nSHLVL=1\nXDG_SESSION_ID=12\nXDG_RUNTIME_DIR=/run/user/1000\nSSH_CLIENT=10.0.2.2 56291 22\nXDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop\nPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\nDBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus\nSSH_TTY=/dev/pts/0\nOLDPWD=/home/vagrant\n_=./hsh\n$\n```\n```\n6. Simple shell 0.1.1\n```\nSimple shell 0.1 +\n* Custom `getline` function\n* Use a buffer to read many chars at once and call the least possible the `read` system call\n* Use of `static` variables\n* Global `getline` function not used\n* [\\_getline](./_getline.c)\n\t* Not implemented:\n* Cursor movement\n```\n7. Simple shell 0.2.1\n```\nSimple shell 0.2 +\n* Custom `strtok` function used\n* [\\_strtok](./_strtok.c)\n```\n8. Simple shell 0.4.1\n```\nSimple shell 0.4 +\n* handle arguments for the built-in `exit`\n* Usage: `exit status`, where status is an integer used to `exit` the shell\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ exit 98\nvagrant@ubuntu-focal:~/simple_shell$ echo $?\n98\nvagrant@ubuntu-focal:~/simple_shell$\n```\n```\n9. setenv, unsetenv\n```\nSimple shell 1.0 +\n* Implement the `setenv` and `unsetenv` builtin commands\n\t* `setenv`\n\t\t* Initialize a new environment variable, or modify an existing one\n\t\t* Command syntax: `setenv VARIABLE VALUE`\n\t\t* Should print something on stderr on failure\n\t* `unsetenv`\n\t\t* Remove an environment variable\n\t\t* Command syntax: `unsetenv VARIABLE`\n\t\t* Should print something on stderr on failure\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ setenv SOME_VAR 13\n$ echo $SOME_VAR\n13\n$ unsetenv SOME_VAR\n$ echo $SOME_VAR\n\n$\n```\n```\n10. cd\n```\nSimple shell 1.0 +\n* Implement the builtin command `cd`:\n\t* Changes the current directory of the process.\n\t* Command syntax: `cd [DIRECTORY]`\n\t* If no argument is given to `cd` the command must be interpreted like `cd $HOME`\n\t* Handles the command `cd -`\n\t* Environment variable `PWD` is updated when you change directory\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ pwd\n/home/vagrant/simple_shell\n$ cd\n$ pwd\n/home/vagrant\n$ cd -\n$ pwd\n/home/vagrant/simple_shell\n$\n```\n```\n11. ;\n```\nSimple shell 1.0 +\n* Handles the commands separator `;`\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ ls /var ; ls /var\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\n$ ls /hbtn ; ls /var\nls: cannot access '/hbtn': No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\n$ ls /var ; ls /hbtn\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nls: cannot access '/hbtn': No such file or directory\n$ ls /var ; ls /hbtn ; ls /var ; ls /var\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nls: cannot access '/hbtn': No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\n$\n```\n```\n12. \u0026\u0026 and ||\n```\nSimple shell 1.0 +\n* Handle the `\u0026\u0026` and `||` shell logical operators\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ ls /var \u0026\u0026 ls /var\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\n$ ls /hbtn \u0026\u0026 ls /var\nls: cannot access '/hbtn': No such file or directory\n$ ls /var \u0026\u0026 ls /var \u0026\u0026 ls /var \u0026\u0026 ls /hbtn\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nls: cannot access '/hbtn': No such file or directory\n$ 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  opt  run  snap  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\nls: cannot access '/hbtn': No such file or directory\n$\n$ ls /var || ls /var\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\n$ ls /hbtn || ls /var\nls: cannot access '/hbtn': No such file or directory\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\n$ 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  opt  run  snap  spool  tmp\n$ 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  opt  run  snap  spool  tmp\n$\n```\n```\n13. alias\n```\nSimple shell 1.0 +\n* Implement the `alias` builtin command\n* Usage: `alias [name[='value'] ...]`\n\t* `alias`: Prints a list of all aliases, one per line, in the form `name='value'`\n\t* `alias name [name2 ...]`: Prints the aliases `name`, `name2`, etc 1 per line, in the form `name='value'`\n\t* `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```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ alias lister='ls -l'\n$ alias pathfinder=\"pwd\"\n$ alias shouter=echo\n$ alias\nlister='ls -l'\npathfinder='pwd'\nshouter='echo'\n$ alias shouter\nshouter='echo'\n$ alias pathfinder\npathfinder='pwd'\n$ lister\ntotal 204\n-rw-rw-r-- 1 vagrant vagrant   136 Feb 21 18:00 AUTHORS\n-rw-rw-r-- 1 vagrant vagrant  4021 Feb 21 18:00 README.md\n-rw-rw-r-- 1 vagrant vagrant   397 Feb 21 18:00 _atoi.c\n-rw-rw-r-- 1 vagrant vagrant  1041 Feb 21 18:00 _getline.c\n-rw-rw-r-- 1 vagrant vagrant   835 Feb 21 18:00 _itoa.c\n-rw-rw-r-- 1 vagrant vagrant   290 Feb 21 18:00 _strcat.c\n-rw-rw-r-- 1 vagrant vagrant   356 Feb 21 18:00 _strcmp.c\n-rw-rw-r-- 1 vagrant vagrant   391 Feb 21 18:00 _strcmpd.c\n-rw-rw-r-- 1 vagrant vagrant   421 Feb 21 18:00 _strcmps.c\n-rw-rw-r-- 1 vagrant vagrant   280 Feb 21 18:00 _strcpy.c\n-rw-rw-r-- 1 vagrant vagrant   357 Feb 21 18:00 _strdup.c\n-rw-rw-r-- 1 vagrant vagrant   267 Feb 21 18:00 _strlen.c\n-rw-rw-r-- 1 vagrant vagrant  1205 Feb 21 18:00 _strtok.c\n-rw-rw-r-- 1 vagrant vagrant   819 Feb 21 18:00 _write.c\n-rw-rw-r-- 1 vagrant vagrant  3028 Feb 21 18:00 alias.c\n-rw-rw-r-- 1 vagrant vagrant  2355 Feb 21 18:00 built_in.c\n-rw-rw-r-- 1 vagrant vagrant   901 Feb 21 18:00 cd.c\n-rw-rw-r-- 1 vagrant vagrant  2982 Feb 21 18:00 env_func.c\n-rw-rw-r-- 1 vagrant vagrant   707 Feb 21 18:00 error.c\n-rw-rw-r-- 1 vagrant vagrant   915 Feb 21 18:00 error.h\n-rw-rw-r-- 1 vagrant vagrant   539 Feb 21 18:00 execute.c\n-rw-rw-r-- 1 vagrant vagrant  2039 Feb 21 18:00 expansions.c\n-rw-rw-r-- 1 vagrant vagrant   829 Feb 21 18:00 file_path.c\n-rw-rw-r-- 1 vagrant vagrant  1067 Feb 21 18:00 help.c\n-rw-rw-r-- 1 vagrant vagrant  2814 Feb 21 18:00 help.h\n-rw-rw-r-- 1 vagrant vagrant  1697 Feb 21 18:00 history.c\n-rwxrwxr-x 1 vagrant vagrant 41760 Feb 21 18:00 hsh\n-rw-rw-r-- 1 vagrant vagrant   557 Feb 21 18:00 input.c\n-rw-rw-r-- 1 vagrant vagrant  3240 Feb 21 18:00 linked_lists.c\n-rw-rw-r-- 1 vagrant vagrant  2121 Feb 21 18:00 memory_func1.c\n-rw-rw-r-- 1 vagrant vagrant   334 Feb 21 18:00 memory_func2.c\n-rw-rw-r-- 1 vagrant vagrant   268 Feb 21 18:00 num_len.c\n-rw-rw-r-- 1 vagrant vagrant  1143 Feb 21 18:00 parser.c\n-rw-rw-r-- 1 vagrant vagrant   272 Feb 21 18:00 pow_b.c\n-rw-rw-r-- 1 vagrant vagrant  1081 Feb 21 18:00 run.c\n-rw-rw-r-- 1 vagrant vagrant  3723 Feb 21 18:00 shell.c\n-rw-rw-r-- 1 vagrant vagrant  2575 Feb 21 18:00 shell.h\n-rw-rw-r-- 1 vagrant vagrant    74 Feb 21 18:00 sometest\n-rw-rw-r-- 1 vagrant vagrant  1267 Feb 21 18:00 str_func.c\n-rw-rw-r-- 1 vagrant vagrant    10 Feb 21 18:00 test_ls_2\n-rw-rw-r-- 1 vagrant vagrant   672 Feb 21 18:00 unalias.c\n$ shouter $PATH\n/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\n$ pathfinder\n/home/vagrant/simple_shell\n$\n```\n```\n14. Variables\n```\nSimple shell 1.0 +\n* Handle variables replacement\n* Handle the `$?` variable\n* Handle the `$$` variable\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ ls /var\nbackups  cache  crash  lib  local  lock  log  mail  opt  run  snap  spool  tmp\n$ echo $?\n0\n$ echo $$\n25100\n$ echo $PATH\n/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin\n$ exit\nvagrant@ubuntu-focal:~/simple_shell$\n```\n```\n15. Comments\n```\nSimple shell 1.0 +\n* Handle comments (`#`)\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ echo $$ # ls -la\n25146\n$ exit\nvagrant@ubuntu-focal:~/simple_shell$\n```\n```\n16. File as input\n```\nSimple shell 1.0 +\n* Usage: `simple_shell [filename]`\n* The 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```\nvagrant@ubuntu-focal:~/simple_shell$ cat test_ls_2\nls\npwd\nls\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh test_ls_2\nAUTHORS    _getline.c  _strcmp.c   _strcpy.c  _strtok.c  built_in.c  error.c    expansions.c  help.h     input.c        memory_func2.c  pow_b.c  shell.h     test_ls_2\nREADME.md  _itoa.c     _strcmpd.c  _strdup.c  _write.c   cd.c        error.h    file_path.c   history.c  linked_lists.c  num_len.c                                                                                                           run.c     sometest    unalias.c\n_atoi.c    _strcat.c   _strcmps.c  _strlen.c  alias.c    env_func.c  execute.c  help.c        hsh        memory_func1.c  parser.c                                                                                                            shell.c  str_func.c\n/home/vagrant/simple_shell\nAUTHORS    _getline.c  _strcmp.c   _strcpy.c  _strtok.c  built_in.c  error.c    expansions.c  help.h     input.c        memory_func2.c  pow_b.c  shell.h     test_ls_2\nREADME.md  _itoa.c     _strcmpd.c  _strdup.c  _write.c   cd.c        error.h    file_path.c   history.c  linked_lists.c  num_len.c                                                                                                           run.c     sometest    unalias.c\n_atoi.c    _strcat.c   _strcmps.c  _strlen.c  alias.c    env_func.c  execute.c  help.c        hsh        memory_func1.c  parser.c                                                                                                            shell.c  str_func.c\nvagrant@ubuntu-focal:~/simple_shell$\n```\n## Error Messages\n* Handles errors when commands fail and prints error message to `stderr`\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ nonexistent\n./hsh: 1: nonexistent: not found\n$ cd nodirectory\n./hsh: 2: cd: nodirectory: No such file or directory\n$ alias notset\n./hsh: 3: alias: notset: not found\n$ setenv noneset\n./hsh: 4: setenv: Syntax error\n$ unsetenv none\n$ exit notint\n./hsh: 6: exit: notint: numeric argument required\nvagrant@ubuntu-focal:~/simple_shellu$\n```\n## Help\n* Enter `help` in shell to get more info on built-in functions\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ help\n\nSimple Shell    Version 1-ALX Software Engineering Team Project(Yasmine B. Ali \u0026 Selasi S. Kporvie)\nThese shell commands are defined in the custom shell.\nType `help' to see this list.\nType `help name' to find out more about the function `name'.\n\nThe following commands are defined:\n\n        alias [name[='value'] ...]      help\n        cd [DIRECTORY]                  history\n        env                             setenv [VARIABLE] [VALUE]\n        exit [status]                   unsetenv [VARIABLE]\n$ help alias\n        alias usage: alias [name[='value'] ...]\n        alias: Prints a list of all aliases, one per line, in the form 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        or overwrites the KEY with new VALUE.\n$ help cd\n        cd usage: cd [DIRECTORY]\n        If no argument is given to cd the command must be interpreted like cd $HOME\n        cd - changes directory to the precious directory\n        the environment variable PWD is updated when cd is used\n$ help env\n        env usage: env\n        Prints out the current envirornment variables.\n$ help exit\n        exit usage: exit status\n        Exits the shell with or without an integer status\n        Last command executed before shell terminates\n$ help history\n        history usage: history\n        Displays history of commands in shell\n$ help help\n        help usage: help COMMAND\n        Displays helpful info about builtins\n$ help setenv\n        setenv usage: setenv VARIABLE VALUE\n        Initialize a new environment variable, or modify an existing one\n        Prints syntax error on stderr on failure\n$ help unsetenv\n        unsetenv usage: unsetenv VARIABLE\n        Remove an environment variable\n        Prints syntax error on sterr on failure\n$\n```\n## Bugs\n* Unable to print alias in the form `alias lister` if lister is an alias with a flag like `'ls -l'`. WOrks fine if alias is not a flag.\n```\nvagrant@ubuntu-focal:~/simple_shell$ ./hsh\n$ alias lister='ls -l'\n$ lister\ntotal 204\n-rw-rw-r-- 1 vagrant vagrant   136 Feb 21 18:00 AUTHORS\n-rw-rw-r-- 1 vagrant vagrant  4021 Feb 21 18:00 README.md\n-rw-rw-r-- 1 vagrant vagrant   397 Feb 21 18:00 _atoi.c\n-rw-rw-r-- 1 vagrant vagrant  1041 Feb 21 18:00 _getline.c\n-rw-rw-r-- 1 vagrant vagrant   835 Feb 21 18:00 _itoa.c\n-rw-rw-r-- 1 vagrant vagrant   290 Feb 21 18:00 _strcat.c\n-rw-rw-r-- 1 vagrant vagrant   356 Feb 21 18:00 _strcmp.c\n-rw-rw-r-- 1 vagrant vagrant   391 Feb 21 18:00 _strcmpd.c\n-rw-rw-r-- 1 vagrant vagrant   421 Feb 21 18:00 _strcmps.c\n-rw-rw-r-- 1 vagrant vagrant   280 Feb 21 18:00 _strcpy.c\n-rw-rw-r-- 1 vagrant vagrant   357 Feb 21 18:00 _strdup.c\n-rw-rw-r-- 1 vagrant vagrant   267 Feb 21 18:00 _strlen.c\n-rw-rw-r-- 1 vagrant vagrant  1205 Feb 21 18:00 _strtok.c\n-rw-rw-r-- 1 vagrant vagrant   819 Feb 21 18:00 _write.c\n-rw-rw-r-- 1 vagrant vagrant  3028 Feb 21 18:00 alias.c\n-rw-rw-r-- 1 vagrant vagrant  2355 Feb 21 18:00 built_in.c\n-rw-rw-r-- 1 vagrant vagrant   901 Feb 21 18:00 cd.c\n-rw-rw-r-- 1 vagrant vagrant  2982 Feb 21 18:00 env_func.c\n-rw-rw-r-- 1 vagrant vagrant   707 Feb 21 18:00 error.c\n-rw-rw-r-- 1 vagrant vagrant   915 Feb 21 18:00 error.h\n-rw-rw-r-- 1 vagrant vagrant   539 Feb 21 18:00 execute.c\n-rw-rw-r-- 1 vagrant vagrant  2039 Feb 21 18:00 expansions.c\n-rw-rw-r-- 1 vagrant vagrant   829 Feb 21 18:00 file_path.c\n-rw-rw-r-- 1 vagrant vagrant  1067 Feb 21 18:00 help.c\n-rw-rw-r-- 1 vagrant vagrant  2814 Feb 21 18:00 help.h\n-rw-rw-r-- 1 vagrant vagrant  1697 Feb 21 18:00 history.c\n-rwxrwxr-x 1 vagrant vagrant 41760 Feb 21 18:00 hsh\n-rw-rw-r-- 1 vagrant vagrant   557 Feb 21 18:00 input.c\n-rw-rw-r-- 1 vagrant vagrant  3240 Feb 21 18:00 linked_lists.c\n-rw-rw-r-- 1 vagrant vagrant  2121 Feb 21 18:00 memory_func1.c\n-rw-rw-r-- 1 vagrant vagrant   334 Feb 21 18:00 memory_func2.c\n-rw-rw-r-- 1 vagrant vagrant   268 Feb 21 18:00 num_len.c\n-rw-rw-r-- 1 vagrant vagrant  1143 Feb 21 18:00 parser.c\n-rw-rw-r-- 1 vagrant vagrant   272 Feb 21 18:00 pow_b.c\n-rw-rw-r-- 1 vagrant vagrant  1081 Feb 21 18:00 run.c\n-rw-rw-r-- 1 vagrant vagrant  3723 Feb 21 18:00 shell.c\n-rw-rw-r-- 1 vagrant vagrant  2575 Feb 21 18:00 shell.h\n-rw-rw-r-- 1 vagrant vagrant    74 Feb 21 18:00 sometest\n-rw-rw-r-- 1 vagrant vagrant  1267 Feb 21 18:00 str_func.c\n-rw-rw-r-- 1 vagrant vagrant    10 Feb 21 18:38 test_ls_2\n-rw-rw-r-- 1 vagrant vagrant   672 Feb 21 18:00 unalias.c\n$ alias\nlister='ls -l'\n$ alias lister\n./hsh: 4: alias: ls: not found\n./hsh: 4: alias: -l: not found\n$\n```\n## Future Tasks\n1. Implement use of cursor\n2. Implement use of symbols like `*`, `\\` and ```\n3. Display colours\n4. Implement `tabs` for autocomplete\n5. Implement more built-in functions\n6. Improve `README.md` and `help` pages\n7. Refactor code\n## Authors\n* Yasmine Ben Ali\n* Selasi S. Kporvie\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelselasi%2Fsimple_shell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamuelselasi%2Fsimple_shell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamuelselasi%2Fsimple_shell/lists"}