Create a small Shell using C language
NAME : HARDIK SAINI
ROLL NO. : 2018391
Pre-requisite in order to perform error free compilation (Make sure that there is enough memory present to fork a child process)
- ) See the headers included in file. Make sure that you have installed all the required modules/packages before including them else it would give error that module not found below are the all headers that included in file
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
make sure that make is installed sudo apt-get install make
- ) If the packages are not installed then the program won't compile
- ) Upon extracting the zipped file open the folder 2018391_CAOS_Shell it would be containing
a. basicFunctions.c
b. basicFunctions.h
c. OuterCommandHandler.c
d. OuterCommandHandler.h
e. shell.c
f. Makefile
- ) Open terminal here and execute command "make"
- ) Upon executing command if you have installed all packages correctly it would have created a file "Shell" without extension file
- ) Execute Shell file by typing ./Shell
- ) now Shell is running…
Assumption is that you're executing make file in same directory.
COMMANDS DESCRIPTION
| COMMAND NAME | FLAGS | DESCRIPTION |
|---|---|---|
| echo | \n | New line |
| \b | Backspace | |
| \c | Suppress Output | |
| history | -c | Clear history |
| -l | First 5 commands | |
| pwd | Flags not available | Current working directory |
| exit | Flags not available | Exit from shell |
| cd | Flags not available | Changes directory |
| ls | -l | Shows list of all files present |
| -a | Show all files (hidden too) | |
| cat | --help (No other flag available) | Opens help |
| --version (No other flag available) | Opens Version of current cat | |
| date | --date={option} (multiple) | Displays date according to option |
| --help | Opens help | |
| --version | Opens Version of date | |
| rm | -i | Asks before deleting |
| -r | Deletes recursively | |
| mkdir | --help (Flags not available) | Display help |
| --version (Flags not available) | Display version | |
| clear | No flags available | Clear output screen |
Test cases
- ) echo apple
- ) echo apple\nbanana
- ) echo appe\ble
- ) history
- ) history -l
- ) history -c
- ) pwd
- ) cd /bin
- ) exit
- ) ls
- ) ls -l
- ) ls -a
- ) ls /
- ) clear
- ) cd /
- ) cat /etc/apt/sources.list
- ) cat --help
- ) cat --version
- ) date --date=yesterday
- ) date --date=tomorrow
- ) date --date=1 month ago
- ) date --date=1 year ago
- ) date --date=1 year
- ) date --help
- ) date --version
- ) mkdir 1
- ) mkdir 1/2
- ) mkdir 1/2/3
- )rm 1 (Error)
- )rm -r 1 (Will delete directories recursively)
- ) rm {file name}
- ) rm -i {filename}
Protection & defenses
I HAVE CREATED SHELL IN SUCH A WAY THAT IF USER EXECUTES SOMES UNKNOWN COMMAND THE SHELL WON'T CRASH RATHER WILL PRINT THE MESSAGE UNKNOWN COMMAND
PROTECTION AGAINST WRONG COMMAND
Example : ls cat
Error directory not found