Skip to content

A working shell based on the Linux Terminal, coded in C

License

Notifications You must be signed in to change notification settings

pratishtha-abrol/Shell-C

Repository files navigation

Linux Shell in C

Overview

This is an attempt to immitate the Linux terminal. It supports most semicolon separated commands, including builtin commands like cd, ls, echo, pwd. Background and Foreground processes are also handled.

  • pwd : prints present working directory.

  • cd : changes directory as per the flags given.

        cd
        cd .
        cd ..
        cd ~
        cd <directory>
  • ls : lists contents of a particular directory based on the flags given. All flags are supported, ordering doesn't matter.

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

        echo <"Hello World">
  • pinfo : lists details of a given process id, of the shell in case process id is not specified.

        pinfo <pid>
        pinfo
  • setenv : setting an environment variable

        setenv a 7
  • unsetenv : unsetting an environment variable

        unsetenv a
  • jobs : prints a list of all jobs executed by the shell

        jobs
  • kjob : send specified signal to the specified job

        kjob 2 9
  • fg : brings a background process to foreground

        fg 1
  • bg : pushes a foreground process to the background

        bg 2
  • overkill : kills all running processes in the shell

        overkill

Foreground and Background processes

  • Foreground processes require the shell to halt for the child process to complete before the shell resumes control.

       vim
       gedit
       emacs
  • Background processes are specifies with a '&' at the end as a flag. These processes run in the background allowing the shell to execute processes simultaneously.

        emacs &
        evince &
        gedit &

Supported Functions

  • The shell supports redirection using <, >, >>
  • The shell supports pipping
  • Input- Output redirection is supported.
  • CTRL + Z and CTRL + C are accepted

Running the shell

In order to run the shell on your local device use the following command :

make
./a.out

Pseudo Home

The shell considers the home directory to be the directory in which the executable ./a.out resides.

Exiting the shell

To exit the shell, use the following command :

quit

Code Files

  • main.c Contains the main driver code for the shell.

  • execute.c Contains the code to execute each command.

  • pwd.c Contains the function to execute builtin pwd command.

  • ls.c Contains the function to execute builtin ls command, and support all flags.

  • cd.c Contains the function to execute builtin cd command.

  • echo.c Contains the function to execute builtin echo command.

  • pinfo.c Contains the function to execute builtin pinfo command.

  • history2.c Contains the function to display history.

  • redirection.c Contains the code for basic redirection.

  • pipeline.c Contains the code for pipelined commands.

  • jobs.c Contains the function to execute builtin jobs command.

  • kjob.c Contains the function to execute builtin kjob command.

  • overkill.c Contains the function to execute builtin overkill command.

  • setenv.c Contains the function to execute builtin setenv command.

  • unsetenv.c Contains the function to execute builtin unsetenv command.

  • fg.c Contains the function to execute builtin fg command.

  • bg.c Contains the function to execute builtin bg command.

  • nightswatch.c Contains the function to execute builtin nightswatch command. Implementation in progress.

About

A working shell based on the Linux Terminal, coded in C

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published