Skip to content

lataba/holbertonschool-simple_shell

Repository files navigation

C - Simple Shell in C

shell_pistacho

What is a SHELL? 🐚

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.

What is this simple shell implementation? ❓❔

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.

How does this Shell work?

This is a flowchart that contains the working flow of the code of this simple shell.

shell

File Structure 📁

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
for all types and functions written for the project.
simple_shell.c
Main function of the project
Main recieve input from the Command Line Interface,
parse and execute it in a while loop.
path_and_env_functions.c
char *store_tokens(char *line)
int str_count(char *str)
char *get_env(char *var_name)
int path_match(char **array_tok)
char *fullpath_func(char *array_tok, char *path_value)
Function that separates the user command line
Function that counts the number of words in a string
Function that gets the value of enviroment variable
Searchs for the command in the path
Function that concatenates the fullpath
execute_functions.c
int fork_child(char **array_tok)
void free_arr(char **array)
Function that creats a child process
Frees an array of char pointers
builtin_functions.c
int shell_exit(void)
int shell_env(void)
int builtin_execute(char **tokens)
int shell_num_builtins(built_s builtin[])
Exits the shell
Function that prints environment variables
Executes the builtin functions
Function that checks the num built-ins

Getting Started

Requirements ✔️

To run this shell, you need to have a C compiler installed on your system. This implementation has been tested on Unix-based system.

Building the Shell 🔌🔧

How to Compile

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.

Running the Shell 💻

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

Functionalities

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.

Limitations

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.

By Laura Ballesté and Nicolás Fernández as part of the Holberton Uruguay study program.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages