An open API service indexing awesome lists of open source software.

https://github.com/pratishtha-abrol/shell-c

A working shell based on the Linux Terminal, coded in C
https://github.com/pratishtha-abrol/shell-c

c linux-commands linux-shell pipeline redirection

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# 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.
``` bash
cd
cd .
cd ..
cd ~
cd
```

* ls : lists contents of a particular directory based on the flags given. All flags are supported, ordering doesn't matter.
``` bash
ls
ls -a
ls -l
ls -la
ls -al
ls
```

* echo : prints a message on the terminal.
``` bash
echo <"Hello World">
```

* pinfo : lists details of a given process id, of the shell in case process id is not specified.
``` bash
pinfo
pinfo
```

* setenv : setting an environment variable
``` bash
setenv a 7
```

* unsetenv : unsetting an environment variable
``` bash
unsetenv a
```

* jobs : prints a list of all jobs executed by the shell
``` bash
jobs
```

* kjob : send specified signal to the specified job
``` bash
kjob 2 9
```

* fg : brings a background process to foreground
``` bash
fg 1
```

* bg : pushes a foreground process to the background
``` bash
bg 2
```

* overkill : kills all running processes in the shell
``` bash
overkill
```

## Foreground and Background processes

* Foreground processes require the shell to halt for the child process to complete before the shell resumes control.
``` bash
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.
``` bash
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 :
``` bash
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 :
``` bash
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.