This repository houses the Shell project,designed to replicate the basic functionalities of a Unix shell. This assignment aims to practice in the use of UNIX system calls and writing a command interpreter on top of UNIX. It offers an opportunity to implement a custom shell that can parse and execute commands, handle environment variables,background processed and support pipes and redirections.
My repository contains 6 versions, each one building on the previous version with incremental improvements and feature enhancements. Starting from a basic shell implementation, subsequent versions progressively introduce new functionalities such as built-in commands, pipe redirection,background processedand command history. This structured approach demonstrates the step-by-step development and refinement of a custom shell, showcasing the evolution of its features and capabilities over time.
- Parsing and execution of shell commands.
- Built-in commands implementation (echo, cd, pwd, env, exit).
- Environment variable management.
- Support for pipes (|) and redirections (> , <).
- Signal handling (Ctrl-D).
Shell is written in C and relies on the following:
- GCC compiler
- Readline library.
- A Unix-based operating system (Linux or MacOS).
USAGE
gcc -o myshellv1 main.c parser.c executor.c prompt.c
./myshellv1
This version contain multiple .c files that are as follows
- Prompt.c: This contains function to generate prompt
- Parser.c: This file contains read_cmd function to read commands from input and tokenize to split commands into arguments.
- Executor.c: This file contains function that forks a new process using fork().In the child process, it attempts to execute the command using execvp()
- Main.c
FEATURES:
Overall The shell generates a dynamic prompt that displays the username, hostname, and current working directory.
The format of the prompt is: PUCITshell:username@hostname:current_directory$ .
We can retrieve Present working directory using pwd
Also we can create , remove and list directory using (mkdir,rmdir,ls) respectively.
We can exit shell using Ctrl-D
USAGE
gcc -o myshell main2.c parser2.c executor2.c prompt2.c
./myshell
This version contain multiple .c files that are as follows
- Prompt2.c: This contains function to generate prompt
- Parser2.c: Theis files handle the parsing of user commands, splitting input lines into arguments and parsing pipe-separated commands.
- Executor2.c: These files manage the execution of commands, including handling piping, redirection, and executing the parsed commands in child processes.
- Main2.c: This file contains the core logic of the shell program, managing user input, history tracking, and the overall flow of command execution
FEATURES:
This shell contain feautures from Version1.
Enhanced Features contain Call to handle_redirection_and_pipes() to process and execute non-builtin commands.
Checks for built-in commands (cd,history)
Errors Faced
execvp() Failure
USAGE
gcc -o myshellv3 main3.c parser3.c executor3.c prompt3.c
This version contain multiple .c files that are as follows
- Prompt.c: This contains function to generate prompt
- Parser.c: Contains logic for parsing commands
- Executor3.c: Handles command execution, including background processes, I/O redirection, and pipes.
- Main.c
FEATURES:
Overall The shell containt functionality for signal handling.
Placing commands (external only) in the background
Avoid Zombies
USAGE
gcc -o myshellv4 version4.c -lreadline
./myshellv4
FEATURES:
The File version4.c contains Functionality of all above version.
Additional Feactures include handling history using Arrow key
Moreover you can re-run command using !
USAGE
gcc -o myshellv5 version5.c -lreadline
./myshellv5
FEATURES:
The File version5.c contains Functionality of all above version integrated into it.
cd: shouldchange the working directory
- exit: shouldterminate your shell
- jobs: provide a numbered list of processes currently executing in the background
- kill:should terminate the process number in the list of background processes returned by jobs by sending it a SIGKILL
- help:lists the available built-in commands and their syntax
USAGE
gcc -o myshell6 version6.c -lreadline
./myshell6
FEATURES:
The shell handles two types of variables: local/user-defined and environment variables.
- get: get variables set by users
- set: set user-defined variables
- list:list variables
This project was developed by Mubashra Iftikhar, a student at FCIT Punjab University,Lahore. It represents a comprehensive effort to understand and replicate the workings of a Unix shell, focusing on process management, signal handling, and user interaction.
The foundation of this shell is inspired by the invaluable resources (https://youtu.be/F7oAWvh5J_o?si=_DK3xzetUApoysV-) provided by Professor Arif Butt.