-
This shell is a command-line interpreter that provides a command line user interface for Unix-like operating systems.
-
It is both an interactive command language and a scripting language, and is used by the operating system to control the execution of the system using shell scripts.
Users type commands which get executed within the session.
$pwd - to print working directory
$cd .. - to change direcory to previous directory
$echo - to print to standard output
$cat - to read a file's content
Below are the files in this repository and a description of the code they contain
Contains the main code of the shell where all the rest of the other functions are used to make the shell run.
Makes the Shell run continously and also listens for signals when a user presses
ctrl + c
Returns
0
on success and1
when something goes wrong as the shell runs
Contains a function that listens for when a user presses
ctrl + c
and prevents the shell session from closing.It prints a new line and clears the standard output instead of interrupting the running shell
Prototype:
void sigint_handler(int sig)
Contains the function
readline()
that gets the user input from standard inputPrototype:
char *readline(void);
Returns:
- The pointer to the string of input the user gave if successfull
- NULL if it fails
Contains the function
splitline(char *line)
that tokenises the user input and stores the resulting tokens in an arrayPrototype:
char **splitline(char *line)
Returns:
- The array of tokens if succesful
- NULL on failure
Contains the function
execute(char **args)
and it's where the actual linux commands are executed.Prototype:
int execute(char **args);
It also uses a few other functions.
Return:
1
on success0
on failure
Contains the function
get_path(char *command)
that gets the full path of given command from thePATH
variablePrototype:
char *get_path(char *command);
Returns:
- A pointer to the full path of the command on success
NULL
on failure
Contains the function
_getenv(char *name)
that finds the environment variable requested by userPrototype:
char *_getenv(char *var);
Returns:
- The value of the environment variable on success
NULL
on failure
Contains the function
tokenize_env(char *path)
that tokenizes thePATH
to return a list of foldersPrototype:
char **tokenize_env(char *path);
Returns:
- An array of directories on success
NULL
on failure
Some custom commands for the shell
Contains the function
_printenv(void)
that pints all the environment variablesPrototype:
void _printenv(void);
It is called by typing the command
env
in the shell
These are some of the helper functions used across most of the core functions.
Most of these are also availabe in the standard library but we were supposed to write the functions ourselves
Contains the functions
_putchar(char c)
that writes a character c to stdoutPrototype:
int _putchar(char c);
Return:
- 1 on success
- -1 on error
Contains the function
_strcat(char *dest, char *src)
that concatonates two strings passed to itPrototype:
char *_strcat(char *dest, char *src);
Returns:
- A pointer to the new string
Contains the function
_strcmp(char *s1, char *s2)
that compares two stringsPrototype:
int _strcmp(char *s1, char *s2);
Returns:
- 0 if equal
- negative value if less than
- positive if greater than
Contains the function
_strlen(char *s)
that finds the length of stringPrototype:
int _strlen(char *s);
Returns:
- Length of the string passed on success
Contains the function
_strncmp(char *str1, char *str2, int n)
that compares n bytes in str1 and str2Prototype:
int _strncmp(char *str1, char *str2, int n);
Returns:
0 if str2 is less than str1
- < 0 if str1 < str2,
- 0 is str1 is equal to str2
This is the man file for the shell
Usage: man ./man_1_simple_shell
Contains all the function prototypes and header files used in this project.