{"id":13782824,"url":"https://github.com/ssharshavardhan/Command-line-interpreter","last_synced_at":"2025-05-11T16:33:04.050Z","repository":{"id":111958565,"uuid":"105478638","full_name":"ssharshavardhan/Command-line-interpreter","owner":"ssharshavardhan","description":"Unix like command line interpreter implemented in c","archived":false,"fork":false,"pushed_at":"2018-02-08T16:21:35.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-08-03T18:16:53.667Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/ssharshavardhan.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}},"created_at":"2017-10-01T22:18:31.000Z","updated_at":"2017-10-22T04:29:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"e008bb2f-fefa-423a-b301-22873b039de9","html_url":"https://github.com/ssharshavardhan/Command-line-interpreter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssharshavardhan%2FCommand-line-interpreter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssharshavardhan%2FCommand-line-interpreter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssharshavardhan%2FCommand-line-interpreter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssharshavardhan%2FCommand-line-interpreter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssharshavardhan","download_url":"https://codeload.github.com/ssharshavardhan/Command-line-interpreter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253595952,"owners_count":21933476,"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":[],"created_at":"2024-08-03T18:01:45.491Z","updated_at":"2025-05-11T16:33:03.816Z","avatar_url":"https://github.com/ssharshavardhan.png","language":"C","funding_links":[],"categories":["C"],"sub_categories":[],"readme":"# Command-line-interpreter\nUnix like command line interpreter implemented in c\n\n------------------------------------ABOUT PROGRAM------------------------------\n\n\nThis program simulates working of command line interface in Unix environment\n\nFunctions implemented :\t1. ls, clear ,vi etc - All external commands \n\t\t\t2. cd ,pwd - Internal commands \n\t\t\t3. rm with support options -r,-f,-v \n\t\t\t4. history n ( even with n omitted)\n\t\t\t5. issue n\n\t\t\t6. Exit\n\t\t\t7. \u003cprogram_name\u003e with redirection operators (\u003e\u003e,\u003e,\u003c\u003c,\u003c,2\u003e)\n\t\t\t8. rmexcept\n\t\t\t9. \u003cprogram_name\u003e m\n\t\t\t10. Echo\n\t\t\t11. Export\n\t\t\t12. '!' operator (!!, !-1, !10,!-10 etc)\n\t\t\t13. Initialize and use environment variables\n\t\t\t14. Pipes “|” (multiple) (Ex: ls | grep 'a' | wc)\n\t\t\t15. Handle Interrupt Signal: On pressing \"Ctrl+C\", the command that is running currently hould be terminated, your program should not terminate.\n\n----COMMAND---------------------DESCRIPTION-----------------------------------------------\n\n\ncd \u003cdirectory_name\u003e\t\tChanges current directory if user has appropriate permissions\nls         \t\t\tLists information about files I the current directory\nrm         \t\t\tDeletes indicated files. Supports options –r, -f, -v\nhistory n \t\t\tPrints the most recent n commands issued by the numbers. If n is omitted, prints all commands issued by the user.\nissue n \t\t\tIssues the nth command in the history once again.\n\u003cprogram_name\u003e \t\t\tCreates a child process to run \u003cprogram_name\u003e. Supports the redirection operators \u003e and \u003c to redirect the input and ouput of the program to indicated files.\nexit \t\t\t\tExits the shell\nrmexcept \u003clist of files\u003e\tRemoves all files except those in \u003clist_of_files\u003e from the current directory\t\n\u003cprogram_name\u003e m\t\tCreates a child process to execute program_name, but aborts the process if it does not complete its operation in m seconds\n\n---------------------------------CODE OVERVIEW---------------------------------------\n\n\nThe shell.c contains the main function which takes the input from user and checks it for pipeline. If pipeline exist it processes the data separately else it passes the data to the functions. \n\nint with_pipe_execute():\nThis function is the initial function which is called for checking the all the command after initial preprocessing . It passes the processed output to function split\n\nint split(char *cmd_exec, int input, int first, int last):\nThis function is responsible for splitting of command and passing it to command function\n\n\nstatic int command(int input, int first, int last, char *cmd_exec):\nthis does the major part of the program. It  checks for various possibilities of commands. The types of commands that are checked are as under:\n1) Internal commands: pwd and cd\n2) echo commands, setting and getting environment variables\n3) redirection handler \n4) PIPE\n5) External commands\nit make use of various funtions like tokenise_redirect_input_output, tokenise_redirect_input, tokenise_redirect_output which internally calls tokenise_commands() for tokenization\n\n\nHelper functions:\ngetcwd():\ngets the current woring Directory\n\nsignal():\nHandle Interrupt Signal\n\nvoid prompt():\ninitiates new Promt \n\nlsh_rmexcept()\nrmexcept function deletes all the files and folders except the ones which are given as its arguments. Arguments can be from 0 to any number of files. whenever rmexcept is called with some arguments(there can be even no arguments) then the function will first get all the files and folders by recursively gather the file names and folders from the current direction where the shell is present. the function to gather files and folders name is get_files_folders() with no argument. The function will return the names of folders and files present in the current directory. After gathering all the information about files and directories, it will see which are the files are present in the arguments given by the user(it will also remove all the white spaces gathered while collection individual file name and directory name and remove it). If that files name is not present in the argument given by the user then the file will be deleted. This will be done for each and every file present in the directory. This will make sure all the files except the ones given by the user as argument are deleted inclusive of directories. strcmp()function is used to compare the argument given by the user and name of files and directories. A function is_dir is created to check whether the given argument is a directory if not a directory then rm command to delete the file is used else rmdir is used to delete the directory. Finally lsh_launch function is used where the file name is passed on and the argument of rm or rmdir is given  accordingly. lsh_launch executes the rm or rmdir command.\n\nget_files_folders()\nthis function uses the dirent.h library of the c and the inbuilt functions already inside that library to gather files and folders. It will open the current directory and if successfully opened then it will use readdir() function to get the file and if the pointer is null it will break the loop else it will gather the information and store and finally return it at the end of the function.\n\nlsh_launch()\nit it will first fork and create a child process and will send the parent to the waiting status while the child is not exited or terminated. while the parent is waiting child will use the execvp function and use rm or rmdir function to delete the files or folders as present in the argument given to this function. if any error it gives an error and return to the shell.\n\nissue_command()\nIt just checks the nth command from history_data array and passes the arguments of nth command\n\nAlso every argument given by user is stored in history.txt and history_data array\n\n------------MAKEFILE---------------\n\nTo directly compile and run program makefile has been provided. Open terminal in the directory having shell.c and makefile and type : \n$make\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssharshavardhan%2FCommand-line-interpreter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssharshavardhan%2FCommand-line-interpreter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssharshavardhan%2FCommand-line-interpreter/lists"}