Skip to content

shincap8/simple_shell

Repository files navigation

_SHELL()


Table of Contents



Authors



Introduction

Project for the end of the first trimester at Holberton School. This project is for us to show what we have learnt in C during these 3 months, the use of loops, conditional, macros, structures, variables, pointers and more, also to test our teamwork skills and our work under pressure.


Description

The shell() compatible command language interpreter that executes commands read from the standard input or from a file.


Installation

In order to run the shell command interpreter, you must install it in your repository by cloning the following (shown below) in your machine running:

git clone https://github.com/shincap8/simple_shell.git

Test

  • In order to compile the function you must run the following line in your shell:
gcc -Wall -Werror -Wextra -pedantic *.c *.h -o hsh

Note: there are two ways of using the command interpreter:

Interactive mode:

 $ ./hsh
($) /bin/ls
hsh main.c shell.c
($)
($) exit
$

Non-interactive mode:

$ echo "/bin/ls" | ./hsh
hsh main.c shell.c test_ls_2
$
$ cat test_ls_2
/bin/ls
/bin/ls
$
$ cat test_ls_2 | ./hsh
hsh main.c shell.c test_ls_2
hsh main.c shell.c test_ls_2
$

Files

  • To read the manual you man run: man ./[FILE] taking into account the structure, for our case it would be man ./man_1_simple_shell
File Name Description and contents
manpage This is the manpage for the shell command, this will help us know how to use the shell and the many uses of it, in here we can find examples and the correct sintaxis of the commands.
_library.h This is the headers file where we can find all the prototypes of our functions and the structures used.
_stdio.c In here we have the puts and putchar function it is used to print characters.
_stdlib.c In here we have the atoi function it is used to make integers into characters, the alloc funcction to allocate memory and the freeall function to free the memory allocated when it is not needed anymore.
_string_0.c Here we can find the function _strtok that splits a string with a delimiter given, _strcat function that concatenates two strings given, _strncmp compares an amount of characters, _strlen counts the characters in a string and _strdup to duplicate strings.
_string_1.c Here we can find the function _strchr that looks for a character in a string and returns a pointer after the match.
additionalFunctions_0.c Here we find the function cantCmds that counts commands, parse function that divide a string in different parts, constructor function who calls the execute, print number who prints numbers, execute that executes the command given.
additionalFunctions_1.c Here we find the function findpath that looks for the path where the command can be executed, path_concat function that concatenate the path and the command, path_copy function copies the path, help_me this function prints the help for every builtin.
builtinsFunctions.c Here we find the function exitF that allows the user to exit, path_concat function that concatenate the path and the command, path_copy function copies the path, help_me this function prints the help for every builtin, unsetF this function is to unset the environment, help function is the one who manage the help print.
generate-authors.sh This script generate the authors file.
helpFunctions.c This file has the messages for the builtin help.
main.c This function has the launch function who starts all the process, the builtin function who calls the builtins, the issame function who compares two strings and the issignals this function is to catch a special key.

Features

A simple shell must work with the path and without the path

  • /bin/ls
  • ls
  • env "this must print the environment"
  • help "this must print the help"
  • exit "let you exit the shell"
  • unsetenv "remove an environment variable"

Examples of use

Below you can find use of some commands.

$ ls -a
$ echo Hola
$ pwd

Here are the result of this actions:

> ls -a
.   additionalFunctions_0.c  AUTHORS              .git             hsh        main.c              README.md  _stdlib.c   _string_1.c
..  additionalFunctions_1.c  builtinsFunctions.c  helpFunctions.c  library.h  man_1_simple_shell  _stdio.c   _string_0.c
> echo hola
hola
> pwd
/home/vagrant/hbn/simple_shell
> exit

Built With

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages