This project implements a simple Unix-style shell in the C programming language, called customshell.
The project is delivered in 3 stages (Stage 1, Stage 2, Stage 3) with incremental functionality.
- Internal Commands
cd– change current directory (or display if no argument). Updates$PWD.clr– clear the terminal screen.dir– list directory contents (likels -al).environ– display all environment variables.echo– print arguments (collapsing multiple spaces/tabs).help– display user manual withmorefilter.pause– pause execution until Enter is pressed.quit– exit the shell.
- Batch Mode
- If invoked as
./customshell batchfile, commands are read and executed from the file.
- If invoked as
- Shell Environment
- Sets environment variable
shell=/path/to/customshell.
- Sets environment variable
- External Commands
- Launch programs using fork + exec, with
parent=/path/to/customshelladded to environment.
- Launch programs using fork + exec, with
- I/O Redirection
- Input
< inputfile - Output overwrite
> outputfile - Output append
>> outputfile - Works for both internal (
dir,environ,echo,help) and external commands.
- Input
- Background Execution
- Commands ending with
&run in the background while shell prompt remains available.
- Commands ending with
- Demonstration Video
- 5-minute video showing:
- Operation of internal commands.
- Running external commands in background (e.g.
./sleepy 5 &). - Demonstration of I/O redirection.
- Code walkthrough (focus on external commands, fork/exec, redirection with
freopen/dup).
- 5-minute video showing:
makefile– builds thecustomshellbinary.customshell.c– main shell implementation.utility.c– supporting functions.customshell.h– header definitions.Stage1/,Stage2/,Stage3/– submission directories for each project stage.
Compile the shell using the provided makefile:
makeThis generates the executable:
./customshellInteractive Mode Run the shell directly:
./customshellPrompt will show the current working directory.
Provide a batch file:
./customshell batchfileExecutes all commands in the file sequentially.
cd /home/user
dir
echo Hello World
environ
pause
quitdir > out.txt
echo Hello >> log.txt
./myprogram < input.txt > output.txt./sleepy 5 &
dircd [dir]– change directory, or show current if none given.clr– clear screen.dir [dir]– list contents of a directory.environ– show all environment variables.echo [text]– print text.help– open manual.pause– wait until Enter is pressed.quit– exit the shell.[program] [args]– run external program.[command] < infile > outfile– redirect input/output.[command] &– run process in background.