This project is a fully functional UNIX-like shell implemented in C. It replicates core shell features such as command execution, redirection, piping, and more. The shell provides a command-line interface to interact with the operating system, similar to bash or sh.
-
Command Prompt
-
Displays the current working directory appended with a custom prompt (
sh>) and reads user input interactively.E.g.,
/mnt/d/C's/UNIX_Shell sh
-
-
Command Execution
- Executes standard system commands using
fork()andexec()system calls. - To be specific all the executable programs listed in the root's bin directory can be executed in this custom shell.
- Example:
pwdwill display the current working directory,lswill list files and folders,mkdirfor creating directory etc.
- Executes standard system commands using
-
Input and Output Redirection
- Supports
<for input redirection. - Supports
>for overwrite output redirection. - Supports
>>for append output redirection. - Example:
cat < input.txt > output.txt
- Supports
-
Command Piping
- Supports piping (
|) between any number of commands. - Example:
cat file.txt | grep "data" | sort | uniq
- Supports piping (
-
Multiple Commands
- Allows multiple commands on the same line separated by a semicolon (
;). - Example:
pwd; ls; whoami
- Allows multiple commands on the same line separated by a semicolon (
-
Conditional Command Execution
- Supports
&&to run the next command only if the previous one succeeds. - Example:
mkdir test && cd test
- Supports
-
Command History
- Maintains a history of executed commands during the shell session. By typing
historyonto the shell, all the commands executed while running the program will be listed.
- Maintains a history of executed commands during the shell session. By typing
-
Signal Handling
- Handles
SIGINT(Ctrl+C) to terminate only the foreground process, not the shell itself.
- Handles
Commands like exit, cd & history were handled in a separate function as thses are not executables from the bin directory so the "execvp()" function won't work for these.
- GCC compiler
- POSIX-compliant system (Linux, macOS, WSL, etc.)
Use the following command to compile the shell:
gcc -o myshell main.cContributions are welcome! To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Make your changes and commit them (
git commit -m "Add feature"). - Push to your fork (
git push origin feature-branch). - Open a pull request.
Please ensure your code follows the project's coding style and includes appropriate comments.