Code Monkey home page Code Monkey logo

simple_shell's Introduction

The StemShell

The shell is a standard command line interpreter for the system. This project is a Holberton School project meant teach students how to emulate a small part of what the shell does. For this assignment, we attempt to immitate how the shell searches for a command. The command we will be using throughout this project will be the ls command.

Overview: Shell

The shell is a command that reads lines from either a file or the terminal, interprets them, and executes other commands. The shell implements a language that has flow control constructs, a macro facility that provides a variety of features in addition to data storage, built-in history, and line editing capabilities. It incorporates many features to aid in interactive use and has the advantage of both interactive and non-interactive use. Commands can be typed directly to the running shell or can be put into a file and the file can be executed as long as permissions to run it are granted via chmod command.

Overview: StemShell

The Stemshell is an emulation of the Shell and attempts to take in and execute the ls command. It features interactive and non-interactive use. The only command that can currently be typed directly to the running shell is the /bin/ls command. Flags can also be typed into the command line and execution of that command is correct.

To use:

vagrant@vagrant-ubuntu-trusty-64:~$ gcc -Wall -Werror -Wextra -pedantic *.c -o hsh
vagrant@vagrant-ubuntu-trusty-64:~$ ./simpleshell
$
  1. Compile with gcc -Wall -Werror -Wextra -pedantic *.c -o hsh
  2. To run, type ./hsh
  3. A prompt should appear. For Stemshell, the prompt is '$'
  4. At the prompt, type in command /bin/ls or /bin/ls -l

For example:

$ /bin/ls
test.c test1.c
$ /bin/ls -l
-rw-rw-r-- 1 vagrant vagrant 122 July 12 23:47 test.c
-rw-rw-r-- 1 vagrant vagrant 122 July 12 23:47 test1.c

Search and Execution

There are three types of commands: shell functions, builtin commands, and normal programs and the command is searched by name in that order. They are executed in different ways.

When the shell function is executed, all the shell positional parameters are set to the arguments of the shell function. In order for the shell to execute commands, it must first take in the arguments, tokenize, check for builtins and alias before forking to process the command.

Shell builtins are executed internally to the shell, without spawning a new process. Currently, the StemShell can only handle the builtin function exit and env.

Requirements

* Allowed editors: vi, vim, emacs
* All your files will be compiled on Ubuntu 14.04 LTS
* Your C programs and functions will be compiled with gcc 4.8.4 using the flags -Wall -Werror -Wextra and -pedantic
* All your files should end with a new line
* A README.md file, at the root of the folder of the project is mandatory
* Your code should use the Betty style. It will be checked using betty-style.pl and betty-doc.pl
* No more than 5 functions per file
* All your header files should be include guarded

Allowed Functions

* access (man 2 access)
* chdir (man 2 chdir)
* close (man 2 close)
* closedir (man 3 closedir)
* execve (man 2 execve)
* exit (man 3 exit)
* fork (man 2 fork)
* free (man 3 free)
* stat (__xstat) (man 2 stat)
* lstat (__lxstat) (man 2 lstat)
* fstat (__fxstat) (man 2 fstat)
* getcwd (man 3 getcwd)
* getline (man 3 getline)
* kill (man 2 kill)
* malloc (man 3 malloc)
* open (man 2 open)
* opendir (man 3 opendir)
* perror (man 3 perror)
* read (man 2 read)
* readdir (man 3 readdir)
* signal (man 2 signal)
* strtok (man 3 strtok)
* wait (man 2 wait)
* waitpid (man 2 waitpid)
* wait3 (man 2 wait3)
* wait4 (man 2 wait4)
* write (man 2 write)
* _exit (man 2 _exit)
* isatty (man 3 isatty)
* fflush (man 3 fflush)

Description of File Structure

  1. AUTHORS - Name of the authors who wrote the simple shell.
  2. header.h - Header file that contains all structs, macros, standard library, and function prototypes.
  3. builtin_id.c - file that contains the following builtin functions:
    • sh_exit - exits the shell.
    • env - prints the current environment.
  4. helper_functions.c - file that contains the following helper functions:
    • _strlen - function that counts the length of a string.
    • _strcat - function that concatenates two strings.
    • _puts - function that prints 1 character at a time.
    • _putchar - function that prints 1 character at a time. Returns an int.
    • _strdup - function that returns pointer to a newly allocated space in memory.
  5. helper_functions2.c - file that contains the following helper functions:
    • _strcmp - function that compares strings.
  6. prompt.c - function that prints the prompt "$ ".
  7. hsh.c - main program that processes the ls command.
  8. man_1_simple_shell - file that contains the man page for StemShell.
  9. README.md - files that contains the description for the assignment. Example of how to use Stemshell is included.

Known Bugs

  • Not all error messages are accounted for
  • Memory leaks exist - check valgrind

Authors

simple_shell's People

Contributors

tope628 avatar

Watchers

 avatar  avatar  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.