This project is about how build our own simple shell program
- git clone https://github.com/LuisPatino92/simple_shell.git
- cd simple_shell
- For compile the shell gcc -Wall -Werror -Wextra -pedantic *.c -o hsh
- Execute ./hsh
# | Directory | Description | |
---|---|---|---|
1 | README.md | ... | |
2 | entry_point.c | Begining entry point to simple shell (main) | |
3 | interactive.c | Functions that interpret the interactive mode and display the new prompt | |
4 | non_interactive_mode | Functions that interpret the non interactive mode and display the new prompt | |
5 | leak_control.c | Special functions for not having many memory leaks | |
6 | interpreter.c | contain funtions to help iterpreter the input command in a simple shell | |
7 | _getline.c | Reads the command from STDIN and tokenizes it | |
8 | execute.c | executes a process | |
9 | aux_strings.c | auxiliar functions for simple_shell | |
10 | aux_strings1.c | auxiliar functions for simple_shell | |
11 | shell.h | Header file with prototypes of the functions | |
12 | man_1_simple_shell | Manual of simple shell | |
13 | AUTHORS | File that lis |
The program simple_shell that takes command from the input
The prompt looks like this:
[#FAKE SHELL] /.../simple_shell $
This simple shell can works in:
- Display a prompt and wait for the user to type a command. A command line always ends with a new line.
- Handle command lines with arguments
- Handle the PATH
- The prompt is displayed again each time a command has been executed.
- The command lines are simple, no semicolons, no pipes, no redirections or any other advanced features.
- The command lines are made only of one word. - If an executable cannot be found, print an error message and display the prompt again.
- Handle errors.
- have to handle the “end of file” condition (Ctrl+D)
- Implement the exit built-in, that exits the shell
- Implement the env built-in, that prints the current environment
- Have own function _getline
- Handle Ctrl+C
- Not have memory leaks
| Prototype | | | Description | |
---|---|
int main(void) | Entry point to simple command line interpeter |
char **_getline(void) | _getline - Reads the command from STDIN and tokenizes it |
void interactive_mode(void) | Interactive commandline interpeter |
void show_prompt(void) | Shows a prompt on the stdout |
void non_interactive_mode(void) | executes one comman passed as pipeline to STDIN |
void execute(char *command, char **args) | executes a process |
void interpeter(char **command, int loop) | Interprets a command |
char *get_valid_exe(char *command) | finds for a valid command to execute |
int include_path(char *command) | Checks if command is a path |
char **path_tokenizer(void) | Tokenizes the path |
char *connect(char *msj1, char *msj2) | Conect two strings |
int _strlen(char *str) | Measure the length of a strings |
int _strncmp(const char *s1, const char *s2, int n) | Compare n bytes of two strings |
char **_strtok(char *str, char delimiter) | Is a double pointer that Splits a string in separated words |
char *write_word(char *str, char delimiter) | Write a word on the desired direction |
int length_d(char *str, char delimiter) | Computes the length of a strings until a delimiter |
- execve (man 2 execve)
- exit (man 3 exit)
- fork (man 2 fork)
- free (man 3 free)
- isatty (man 3 isatty)
- malloc (man 3 malloc)
- read (man 2 read)
- signal (man 2 signal)
- stat (__xstat) (man 2 stat)
- wait (man 2 wait)
- write (man 2 write)
-->
$ ls
AUTHORS aux_strings.c execute.c leak_control.c testing
README.md aux_strings1.c hsh man_1_simple_shell
_getline.c built_ins.c interactive.c non_interactive.c
a.out entry_point.c interpeter.c shell.h
$ ls -l
total 84
-rw-r--r-- 1 luna luna 190 Nov 25 18:55 AUTHORS -rw-r--r-- 1 luna luna 4468 Nov 25 23:20 README.md
-rw-r--r-- 1 luna luna 890 Nov 25 23:23 _getline.c
-rwxr-xr-x 1 luna luna 18496 Nov 25 17:58 a.out
-rw-r--r-- 1 luna luna 2583 Nov 25 19:09 aux_strings.c
-rw-r--r-- 1 luna luna 1839 Nov 25 19:36 aux_strings1.c
-rw-r--r-- 1 luna luna 564 Nov 26 11:27 built_ins.c
-rw-r--r-- 1 luna luna 230 Nov 25 15:12 entry_point.c
-rw-r--r-- 1 luna luna 339 Nov 25 19:42 execute.c
-rwxr-xr-x 1 luna luna 18496 Nov 25 19:10 hsh
-rw-r--r-- 1 luna luna 1406 Nov 25 16:56 interactive.c
-rw-r--r-- 1 luna luna 2674 Nov 25 10:55 interpeter.c
-rw-r--r-- 1 luna luna 1910 Nov 25 19:46 leak_control.c
-rw-r--r-- 1 luna luna 582 Nov 25 16:57 man_1_simple_shell
-rw-r--r-- 1 luna luna 382 Nov 26 11:27 non_interactive.c
-rw-r--r-- 1 luna luna 1327 Nov 25 19:09 shell.h
drwxr-xr-x 1 luna luna 4096 Nov 25 10:55 testing
$ /bin/ls
AUTHORS _getline.c aux_strings.c built_ins.c execute.c interactive.c leak_control.c non_interactive.c testing
README.md a.out aux_strings1.c entry_point.c hsh interpeter.c man_1_simple_shell shell.h
$ /bin/ls /bin/ls /bin/ls
/bin/ls /bin/ls
$ echo simple example
simple example
$ inexistent_command
./hsh: 1: inexistent_command: not found
- LUIS ALEJANDRO PATIÑO ARBOLEDA
- GIRALUNA GOMEZ LONDOÑO