Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kalpishs/Unix-Shell-Implementation-in-C
Simulate the Working of Command Line Interface in Unix-like Environment. Implemented Piping, redirection, history, environment variables,external-internal commands etc using family of system calls.
https://github.com/kalpishs/Unix-Shell-Implementation-in-C
Last synced: 3 months ago
JSON representation
Simulate the Working of Command Line Interface in Unix-like Environment. Implemented Piping, redirection, history, environment variables,external-internal commands etc using family of system calls.
- Host: GitHub
- URL: https://github.com/kalpishs/Unix-Shell-Implementation-in-C
- Owner: kalpishs
- Created: 2016-05-07T13:26:00.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-17T18:28:14.000Z (over 8 years ago)
- Last Synced: 2024-02-17T06:36:12.470Z (9 months ago)
- Language: C
- Homepage:
- Size: 122 KB
- Stars: 25
- Watchers: 2
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
===========================================================================================================================
UNIX SHELL IMPLEMENTATION IN C
===========================================================================================================================
This program simulates the working of command line interface in Unix-like environment. Implemented Functionalities are as under:1. Execute all the External commands (ls, clear, vi etc.)
2. Implement Internal commands: cd, pwd
3. Initialize and use environment variables
4. Print environment variables using echo command
5. Redirection operators: STDIN, STDOUT, STDERR (>>,>,<<,<,2>)
6. Support for history command and '!' operator (history, !!, !-1, !10,!-10 etc)
7. Pipes “|” (multiple) (Ex: ls | grep 'a' | wc)
===========================================================================================================================
Input/Output Format
===========================================================================================================================Input from the 'stdin' in an infinite loop till an “exit” is entered.
The corresponding output should be printed to 'stdout'.Ex:
assume that PWD==home/userShell name: My_Shell
bash prompt:~$ ./a.out
My_Shell:/home/user$ ls
shell.c history.txt a.out
My_Shell:/home/user$ gfhj
gfhj: command not found
My_Shell:/home/user$ exit
Bye...
bash prompt:~$
===========================================================================================================================
Implementation Details
===========================================================================================================================The 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.
int with_pipe_execute():
This function is the initial function which is called for checking the all the command after initial preprocessing . It passes the processed output to function splitint split(char *cmd_exec, int input, int first, int last):
This function is responsible for splitting of command and passing it to command function
static int command(int input, int first, int last, char *cmd_exec):
this does the major part of the program. It checks for various possibilities of commands. The types of commands that are checked are as under:
1) Internal commands: pwd and cd
2) echo commands, setting and getting environment variables
3) redirection handler
4) PIPE
5) External commands
it make use of various funtions like tokenise_redirect_input_output,tokenise_redirect_input,tokenise_redirect_output which internally calls tokenise_commands() for tokenization
Helper functions:
getcwd():gets the current woring Directory
signal():
Handle Interrupt Signal
void prompt():
initiates new Promt