This repository contains the source code for a custom UNIX shell, developed by Subhan Ali as part of an Operating Systems assignment.
The shell is built in six versions, with each version adding new functionalities, culminating in a feature-rich command-line interface that supports external commands, I/O redirection, background processing, command history, built-in commands, and variable management.
- Displays a prompt and accepts user input for external commands.
- Uses
forkandexecto execute commands. - Waits for each command to complete before showing the prompt again.
- Exits on
CTRL+D.
- Added support for input (
<) and output (>) redirection. - Allows commands like
mycmd < infile > outfileto redirectstdinandstdout.
- Supports running processes in the background using
&at the end of a command. - Returns the prompt immediately after launching background processes.
- Maintains a history of the last 10 commands.
- Supports repeating commands using
!number(e.g.,!1for the first command) and!-1for the last command.
- Implements built-in commands including:
cd: Change the working directory.exit: Terminate the shell.jobs: List currently running background jobs.kill: Terminate a specified background job.help: Display a list of available built-in commands.
- Adds support for local and environment variables.
- Allows assigning values to variables and retrieving their values.
- Implements a simple storage system to distinguish between local and environment variables.
- External Command Execution: Supports standard UNIX commands by searching paths and executing binaries.
- I/O Redirection: Enables redirection of
stdin,stdout, and append mode for output. - Background Process Handling: Run processes in the background without waiting for completion.
- Command History: Access previous commands for quick execution.
- Built-in Commands: Includes custom commands such as
cd,exit,jobs,kill, andhelp. - Variable Management: Handles user-defined and environment variables, allowing dynamic variable assignment.
- Clone this repository to your local machine.
git clone https://github.com/codebysubhan/operating-systems.git
- Navigate to the directory.
cd operating-systems - Compile the shell program.
gcc shell_v1.c -o shell_v1
Run the shell by executing the compiled binary:
./shell_v1