A shell is a program that provides a command-line interface for interacting with an operating system. It acts as a command interpreter between the user and the system kernel. A shell reads input from the user, interprets it, and executes the requested commands or programs. In other words, a shell is a user interface that allows users to interact with the operating system using a command-line interface. The shell provides a prompt, where users can enter commands and run various tasks such as navigating the file system, managing processes, and executing programs.
This is a simple shell implementation in C that can work in both interactive and non-interactive mode. The shell can run commands and support basic shell functionalities.
This is a flowchart that contains the working flow of the code of this simple shell.
This table provides a detailed description of the files used for this shell implementation. In these files are the functions that constitute the program.
File | Prototypes | Description |
---|---|---|
shell.h |
Header of the project |
Header file containing definitions and prototypes |
simple_shell.c |
Main function of the project |
Main recieve input from the Command Line Interface, |
path_and_env_functions.c |
char *store_tokens(char *line) |
Function that separates the user command line |
execute_functions.c |
int fork_child(char **array_tok) |
Function that creats a child process |
builtin_functions.c |
int shell_exit(void) |
Exits the shell |
To run this shell, you need to have a C compiler installed on your system. This implementation has been tested on Unix-based system.
To use this implementation of a simple shell, follow these steps:
1 - Download and save the files given above, in a single directory or clone this repository in a directory of your computer.
2 - To build the shell, navigate to the directory where you have downloaded the source code and run the following command:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh
This will create an executable file named "hsh" in the same directory.
To start the shell in interactive mode, simply run the hsh command. This will start the shell and you can start typing commands.
$ ./hsh
And you can run it in non-interactive mode:
$ echo "ls -la" | ./hsh
The shell is capable of executing commands, searching paths in the system, and managing processes. Some of the available commands are:
- env: Displays environment variables.
- exit: Exits the shell.
- echo: Displays a message on the standard output.
- pwd: Prints the working directory.
This is a simple shell implementation and it has some limitations compared to a full, advanced shell, so there may be some tasks that cannot be performed.
To mention some limitations: This shell does not support background processes. This shell does not handle all possible error conditions. This shell implementation does not support running pipes or standard input/output redirection.