/simple_shell

Simple Command Line interface replicated in C

Primary LanguageC

0X16.C - Simple_shell

S/o Julien Barbier

Simple shell :

Holberton School 

Table of Contents :

Description :

simple_shell is a command line interpreter, or shell, in the tradition of the first Unix shell written by Ken Thompson in 1971. This shell is intentionally minimalistic, yet includes the basic functionality of a traditional Unix-like command line user interface.

Files :

  • [Function] :

    • main - main function with shell body
    • exevc - recreate execve funtcion
    • exit - exit the simple shell
    • memcpy - recreate memcpy funtcion
    • prompt - recreate prompt funtcion
    • realloc - recreate realloc funtcion
    • echo_command - implementation of echo command in shell
    • node_function - Add a node a the end of the linked list
    • _atoi - Convert the first number of a str to an interger.
    • execut_command - Test and execute a command
    • sep_to_space - Change \t and \r into a space
    • signal_handler - Catch a Ctrl - C and disable him
    • _getline - Check the number of characters on a specific line
  • [PATH function] :

  • [str function] :

    • strcmp - function compares the two strings
    • strdup - function returns a pointer to a new string which is a duplicate of the string
    • strlen - function calculates the length of the string pointed to by s
    • strtok - breaks a string into a sequence of zero or more nonempty tokens
  • [check] :

    • check_built_in - check all built-in command before the first fork
    • check_user_input - Put a '\0' at the end of the input and check if there is any comment
  • [environement function] :

  • [free memory file] :

    • free_all - free all malloc / realloc / buffer
  • [Header file] :

    • shell.h - Header file contain all prototype / standart library / and structure
  • [Helping files] :

Requirements :

Usage :

Features :

  • uses the PATH
  • implements builtins
  • handles command line arguments
  • custom strtok function
  • uses exit status
  • shell continues upon Crtl+C (^C)
  • handles comments (#)
  • handles ;
  • custom getline type function
  • handles && and ||
  • aliases

Builtins :

  • exit
  • env
  • setenv
  • unsetenv
  • cd
  • help

Example of Use :

Run the executable in your terminal after compiling:

gcc -Wall -Werror -Wextra -pedantic -std=gnu89 shell.h *.c -o hsh

./hsh

exemple:

./hsh
$  # type you command here
$ ls
    bermuda_triangle.c I_hate_simple_shell.c README.md
$ echo $$
    24413
$ env
    SHELL=/bin/bash
    COLORTERM=truecolor
    TERM_PROGRAM_VERSION=1.62.3
    LC_ADDRESS=C.UTF-8
    LC_NAME=C.UTF-8
    LC_MONETARY=C.UTF-8
    PWD=/home/vagrant/Simple_shell
    LOGNAME=vagrant
    XDG_SESSION_TYPE=tty
    VSCODE_GIT_ASKPASS_NODE=/home/vagrant/.vscode-server/bin/ccbaa2d27e38e5afa3e5c21c1c7bef4657064247/node
    MOTD_SHOWN=pam
    ...
$ exit # leave de shell ctrl C hase disable

AUTHORS :

for Holberton School