Coder Social home page Coder Social logo

custom-shell's Introduction

HOLBERTON PROJECT: simple_shell

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. Standard functions and system calls employed in simple_shell include: access, execve, exit, fork, free, fstat, getline, malloc, perror, signal, stat, wait, write.

File Structure

  • holberton.h - program header file

  • .simple_shell_history - File where history's historial must be saved

  • builtins.c - major builtin functions

    • check_for_builtins - checks if the command is a builtin
    • new_exit - exits the shell with the option of a specified status
    • _env - prints the current shell's environment variables to the standard output
    • new_setenv - create a new environment variable, or edit an existing variable
    • new_unsetenv - removes an environment variable
  • builtins2.c - more builtin functions

    • _new_cd - Changes the current working directory .
  • enviroment - more builtin functions

    • make_enviroment - make the shell environment from the environment.
    • free_env - free the shell's environment
  • history.c - history builting and funcions related.

    • add_nodeint - Add node in the beginning
    • free_listint - free pointers related with malloc
    • new_history - Print the list of a single list
    • _puts3 - writes a string to standard output
    • print_message - print a string to standart output
  • add_functions.c - helpers functions for fork_child function

    • _strcmp - compares two strings
    • error_printing - Prints a message error when a comand is not found.
    • exec_error - Prints exec errors.
  • helper_functions.c - Functions to manage error messages and utils

    • _puts_error - print a string to sdandart error
    • prints_error_msg - prints error messages to standard error
    • integer_converter - converts an unsigned int to a string
    • atoi - converts a string into an integer
  • setenv_functions.c - helper functions for setenv builting

    • add_value - create a new environment variable string
    • find_key - finds an environment variable
    • add_key - create a new environment variable
  • memory_allocation.c - memory allocation functions

    • _realloc - a custom realloc function for arrays of pointers
  • new_strtok.c - custom strtok and helper functions

    • check_match - checks if a character matches any in a string
    • new_strtok - a custom strtok for the shell
    • build_path - Combines two strings one representing the path directory and another representing the command file.
  • fork_child.c - functions related to executing commands

    • fork_child - Creates a child in order to execute another program.
    • path_finder - Acts as an interface for functions that will be able
    • to find the full path of a program.
    • find_env_index - Finds the index of an environmental variable.
    • tokenize_path - Separates a string of path as an array of
    • strings containing the path directories.
    • search_directories - Looks through directories stored in path_tokens
    • for a specific file aka command.
  • simple_shell.c - essential functions to the shell

    • main - the main function of the program
    • sig_handler - handles SIGINT
  • strfunctions.c - functions related to string manipulation

    • _puts - writes a string to standart output
    • _strdup - duplicates a string
    • _strcmpr - compares two strings
    • _strcat - concatenates two strings with a / in the middle
    • _strlen - calculates the length of a string
  • tokenizer.c - tokenizing function

    • tokenizer - creates an array of tokens from a buffer with a specified delimiter
    • tokenize -tokenizes a buffer with a delimiter just use for for_child
    • token_interface - token interface
    • count_token - token's count
  • new_help.c - Help builting and functions

    • new_help - help builtin command
    • new_help_help - help builtin command help
    • new_help_exit - help builtin command exit
    • new_help_cd - help builtin command cd
    • new_help_env - help builtin command env
  • more_help_functions.c - More help functions

    • new_help_history - help builtin command history
    • new_help_unalias - help builtin command unalias
    • new_help_unset - help builtin command unset
    • new_help_unsetenv - help builtin command unsetenv
    • new_help_setenv - help builtin command setenv
  • more_help_functions2.c - More help functions

    • new_help_alias - help builtin command alias
    • new_help_else - Error message if not command found
  • print_functions.c - More utils

    • print_str - Prints a string character by character.
    • _write_char - Writes a character to stdout
    • print_number - Prints an unsigned number
  • man_1_simple_shell - Shell Man page

Directories

  • helpfiles - arguments files for help building.
  • Mishell - testing shell apart.
  • shell2 - backup to test shell, outdated version.

Requirements

simple_shell is designed to run in the Ubuntu 14.04 LTS linux environment and to be compiled using the GNU compiler collection v. gcc 4.8.4 with flags-Wall, -Werror, -Wextra, and -pedantic.

Installation

 - Clone this repository: `https://github.com/yoyogold-a11/shelltestenviroment.git`.
 - Change directories into the repository: `cd simple_shell`
 - Compile: `gcc -Wall -Werror -Wextra -pedantic *.c -o hsh`
 - Run the shell in interactive mode: `./hsh`
 - Or run the shell in non-interactive mode: example `echo "pwd" | ./hsh`

Usage

The simple_shell is designed to execute commands in a similar manner to sh, however with more limited functionality. The development of this shell is ongoing. The below features will be checked as they become available (see man page for complete information on 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
  • variable replacement

Builtins

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

Example of Use

Run the executable in your terminal after compiling:

$ ls
add_functions.c           helpfiles            more_help_functions2.c  shell2
builtings.c               holberton.h          more_help_functions.c   strfunctions.c
enviroment.c              hsh                  new_help.c              tokenizer.c
env_unsetenv_functions.c  main.c               new_strtok.c
fork_child.c              memory_allocation.c  print_functions.c
helper_functions.c        Mishell              README.md
$ help 2
./hsh: 5: help: no help topics match: `2'.  Try `help help' or `man -k 2' or `info 2'.
$ help cd
cd: cd
	Change the shell working directory.

	Change the current directory to DIR.  The default DIR is the value of the
	HOME shell variable.

	The variable CDPATH defines the search path for the directory containing
	DIR.  Alternative directory names in CDPATH are separated by a colo
n (:).
	A null directory name is the same as the current directory.  If DIR begins
	with a slash (/), then CDPATH is not used.

	Exit Status:
	Returns 0 if the directory is changed, and if $PWD is set successfully when
	-P is used; non-zero otherwise.
$ pwd
/home/shell_test/shelltestenviroment
$

Bugs

At this time, there are no known bugs.

Authors

Joshua Claudio Enrico | GitHub

Luis Escobedo | GitHub

License

simple_shell is open source and therefore free to download and use without permission.

custom-shell's People

Contributors

joshua-enrico avatar luisdev20 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.