GithubHelp home page GithubHelp logo

simple_shell-1's Introduction

0x16. C - Simple Shell

logo

Description


This team project is part of the first year curriculum of Holberton School. Simple Shell is a UNIX command line interpreter that replicates the sh program.

What we learned:

  • How a shell works and finds commands
  • Creating, forking and working with processes
  • Executing a program from another program
  • Handling dynamic memory allocation in a large program
  • Pair programming and team work
  • Building a test suite to check our own code
  • How to manipulate the environment of the current process
  • What is the difference between a function and a system call
  • What are the three prototypes of main
  • How does the shell use the PATH to find the programs
  • How to execute another program with the execve system call
  • How to suspend the execution of a process until one of its children terminates*

Compile and run


  1. Git clone all this respository to your local directory.
$ git clone https://github.com/carlosz22/test_shell.git
  1. Compile the program.
$ make all
  1. Execute the shell.
$ ./shell

Note: You can also run this shell in non-interactive mode, by simply piping your desired commands into the shell executable.

Usage


  • Prints a prompt and waits for a command from the user
  • Creates a child process in which the command is checked
  • Checks for built-ins, aliases in the PATH, and local executable programs
  • The child process is replaced by the command, which accepts arguments
  • When the command is done, the program returns to the parent process and prints the prompt
  • The program is ready to receive a new command
  • To exit: press Ctrl-D or enter "exit" (with or without a status)
  • Works also in non interactive mode

Examples


# Interactive Mode
$ /bin/ls
foo main.c coquille.c README.md tests croissant.c
$ pwd
/home/vagrant/simple_shell
$ ls -l
total 60
drwxrwxr-x 7 vagrant vagrant  4096 Apr  7 01:48 foo
-rw-rw-r-- 1 vagrant vagrant   148 Apr  7 00:00 main.c
-rwxrw-r-- 1 vagrant vagrant    28 Apr  7 15:35 coquille.c
$ baguette
./shell: No such file or directory
# Non-interactive Mode
$ echo "ls -l" | ./shell

$ ls -l
total 60
drwxrwxr-x 7 vagrant vagrant  4096 Apr  7 01:48 foo
-rw-rw-r-- 1 vagrant vagrant   148 Apr  7 00:00 main.c
-rwxrw-r-- 1 vagrant vagrant    28 Apr  7 15:35 coquille.c

Builtin Commands


This shell supports a variety of builtin commands:

cd - change directory

env - list the current environment variables

exit - exit the shell

help - display help for a builtin command

Note: To read the help information and syntax for a particular builtin command, run the following from the shell prompt:

$ help <builtin command>

Files


File Content
main.c entry point, executing function
shell.h function prototypes, standard libraries, structs
hsh_readline.c read line functions
hsh_parseline.c string to tokens parsing functions
hsh_execute.c functions dealing with the shell builtins and command execution
hsh_getenv.c functions dealing with environment variable
hsh_splitpath.c functions that check the PATH for commands
hsh_string.c function dealing with string conversion and operations
more_functions.c conversion between string and number functions
man_1_simple_shell Simple Shell man page (man ./man_1_simple_shell)

Authors


simple_shell-1's People

Contributors

carlosz22 avatar cavb28 avatar

Watchers

 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.