A custom terminal for Linux supporting bash commands with support for almost all built in functions either through system call or custom written built in function. Takes care of input output redirection with
ls > test.txt
sort < in.txt > out.txt
Does pipe handling (with IO redirection too)
ls | cat | grep test > out.txt
GCC Version >= 10.2.0
Will work for lower Versions also but there could be unexpected warnings and errors.
Run The Following command in the dir where you cloned the repo
make
./terminal
or Copy Paste the following
git clone https://github.com/vjspranav/C_Shell -b v1
cd C_Shell
make
./terminal
- echo
echo string
Ignoring extra whitespaces prints on shell
- ls
ls <dirname> <dir2name> <filename> [options]
ls or ls -a or ls -l or ls -al/la with dirname(s) and/or filename(s) and/or no arguments list it out. Tried to mimic actuall shell output/performace with multiple folders given or files given.
- cd
cd dirpath
dir path could be relative or absolute. '.' would be in same dir, '..' to previous dir, '~' for terminal execute dir. Relative wrt to '~' is also allowed.
- history
history <num>
last 10 commands in history would be printed if no num is provided else last num number of commands will be printed. (Stores only last 20 commands)
- pwd
pwd
Print current dir path
- pinfo
pinfo
will give
pid -- 231
Process Status -- {R/S/S+/Z}
memory -- 67854{Virtual Memory}
Executable Path -- ~/a.out
or
pinfo pid
will give
pid -- (pid)
Process Status -- {R/S/S+/Z}
memory --123456 {Virtual Memory}
Executable Path -- /usr/bin/gcc
Gives info of the process with process id pid, if no pid is given the info of shell is shown.
- setenv
setenv <name> <value>
Set value to to variable name, if variable exists it's value is not overwritten, if no value is provided string.
- unsetenv
unsetenv <name>
Clears value of variable name.
- jobs
jobs
will give
<vjspranav@archlinux:~>$ jobs
[1] Stopped nano with id=21076
[2] Stopped vim with id=21078
[3] Running sleep with id=21081
Will print a list of background running processes with jobnumber and pid
- kjob
kjob <jobnumber> <signal>
Will send kill signal signal to process id with job number which we get from jobs
- fg
fg <job number>
Brings the running or stopped background job corresponding to jobnumber to the foreground, and changes its state to running. The shellshould throw an error if no job with the given job number exists
- bg
bg <job number>
Changes the state of a stopped background job to running (in thebackground). The shell should throw an error if no background jobcorresponding to the given job number exists.
- overkill
overkill
Kills all created background processes.
All headers files have Macros and function definations for global accesibility of the functions in the respective C files
- makefile
Compiles all objects and starts the terminal
- headers.h
Has all the header Files required across the complete Terminal code also has the inclusion for childHandler.
- commands.h
Has all the header File inclusions required for custom functions.
- main.c
Main Driver Code That displays prompt and accepts input in a loop, also ahs the signal handler for when a child exits.
- prompt.c
Gets the username and host name and creates the prompt part of shell
- input.c
Takes the input from a string, parses it at semicolons and in a loop each command is space separated and sent to command handler as a 2d array.
- commadHandler.c
has a few functions that take care of stripping whitespaces checking if the command is custom function or built in. If built in checks whether to execute in foreground or background.
- childHandler.c
Has a killChild function that starts when a child process has completed successfully and has a kill all function that kills all paused childs in background on terminal exit.
- pipeHandler.c
Has the code that handles pipes.
- cd.c
Has code for changing directory.
- echo.c
Has a code for echoing whatever is given (Ignores '"' and environment variables)
- history.c
Functions that store the history max upto 20 in a file across sessions.
- ls.c
Functions for listing all files and folder with/without hiddem with/without all details.
- pwd.c
Function that prints current absolute dir
- pinfo.c
Prints Process info given pid else prints the info of terminal
- env.c
Has code for setenv and unsetenv
- fgbg.c
Has code for fg bg and kjob
- signalHandler
Handles signal interrupts ctrl+C and ctrl+Z