Giter Club home page Giter Club logo

linux-c-shell's Introduction

Linux-C-Shell

Overview

This shell is a complete working linux shell. It supports most linux shell functionalities including semicolon separated commands, piping, redirection, and all basic linux commands etc. Foreground and Background processes can also be executed. The commands that are supported are as follows :

  • pwd : prints the present working directory.

  • cd : changes the directory based on the flags given.

    • cd
      cd .
      cd ..
      cd ~
      cd <directory>
  • ls : lists the contents of a particular directory based on the flags given.

    • ls
      ls -a
      ls -l
      ls -al
      ls -la
      ls <directory>
  • echo : prints a message on the terminal

    • echo <"Hello World">
  • pinfo : lists the details of a particular process (may be based on a process ID that is given).

    • pinfo
      pinfo <pid>
  • Foreground Processes: Processes that require the terminal to halt until their completion. Example:

    • vi
      emacs
  • Background Processes: Processes that run simultaneuosly without interrupting the terminal. Example:

    • emacs &
  • Input output redirection : Redirects input or output to appropriate files. Example:

    • cat file1.txt > file2.txt
      sort < sort.txt > sorted.txt
  • Piping commands : Pipes two or more commands together. Example:

    • cat test.txt | grep a
  • Piping with redirection : Example :

    • sort < sort.txt  | grep a | wc > lines.txt
  • setenv : setting new environment variables. Example :

    • setenv a 15
  • unsetenv : unsetting an environment variable

    • unsetenv a
  • jobs : prints all the background jobs

    • jobs
  • kjob : Sends a signal to a particular job number

    • kjob 1 9
  • fg : brings a running or a stopped background job with given job number to foreground.

    • fg 1
  • bg : changes a stopped background job to a running background job.

    • bg 1
  • overkill : kills all background process at once.

    • overkill
  • The terminal also supports

    • CTRL + C

Running the Shell

In order to run the shell run the following command.

    make
    ./a.out

Exiting From the shell

To exit from the shell, use the command

quit

Pseudo Home

If the executable is being run from a different directory, specify the corresponding path.
The "Pseudo Home" directory for the shell will be the directory in which the executable ./a.out resides.

Code Files and Files

  • main.c:

    • prompt(): function to print th shell promt.

    • loop(): runs the main loop of the code for the continuous execution of the shell.

    • extract_command(): take the string parsed as input and returns the extracted command as a command array.

    • piping(): checks for piping in the command.

    • red_flag_check(): checks for redirections flag check.

  • pwd.c:

    • pwd(): function that prints the present working directory.
  • ls.c:

    • The flags -a, -l, -la, -al can be used. Complete or absolute path of a directory can also be provided to list the contents of that directory.

    • ls_a(): lists files and directories including hidden files.

    • ls_l(): lists all information about files and directories excluding hidden files.

    • ls_al(): lists all information about files and directories including hidden files.

    • ls_basic(): simply lists all files and directories.

    • ls_call(): driver function to choose amongst the above functions.

    • flag_check(): takes in the command as input and return the correct flag given in the command

  • cd.c:

    • cd (): Absolute or relative path of a directory must provided. The directory will then be changed the argument provided.
  • echo.c:

    • echo_func(): Prints a string argument on the terminal. Handles cases with and without quotes.
  • pinfo.c():

    • pinfo(): Provides details about currently active/running processes. A particular process ID can also be provided as an argument to obtain its details.
  • foreground.c:

    • foreground(): Forks the existing process and runs a child process in the foreground. The parent process resumes once the child terminates and waits till then.
  • background.c:

    • background(): Forks the existing process and runs a child process in the background. The parent process continues to run alongside the child process. Once the child terminates, the exit satus of the child process prints on the screen.

    background processes for built in commands are not supported

  • history.c:

    • update_hist(): Every time a new command is given to the shell, the command is added to the array to be printed later.

    • print_hist(): Prints the history upto 10 commands earlier.

linux-c-shell's People

Contributors

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