This project is a custom shell implemented in C. The shell reads user input, parses and executes commands by forking new processes, and supports basic piping between commands. It utilizes the fork()
and execvp()
system calls to create and manage child processes.
-
Command Execution:
- Reads and executes commands specified by the user.
- Supports absolute paths (e.g.,
/bin/ls
) and path expansion using thePATH
environment variable. - Executes commands with up to four command-line arguments.
-
Process Management:
- Forks a new process for each command.
- Waits for child processes to complete and prints their PID and return status.
-
Error Handling:
- Reports errors on encountering input errors.
- Gracefully exits on EOF without reporting errors.
- Handles input up to a 187-byte buffer size without overflow.
-
Piping:
- Supports piping of commands, allowing the output of one command to be used as input for the next.
- No limit on the number of piped commands, constrained only by command line length.
- GCC (GNU Compiler Collection): Ensure you have GCC installed on your system. You can install it via package managers like
apt
,yum
, orbrew
.
-
Clone the Repository:
git clone https://github.com/jjestrada2/custom-c-shell.git cd custom-c-shell
-
Compile the Project:
make
-
Running the Shell:
./shell
-
Executing Commands:
-
Enter commands directly into the shell prompt. Example:
/bin/ls
-
Enter commands with arguments. Example:
/bin/echo Hello, World!
-
Use pipes to chain commands. Example:
cat myfile.txt | wc -l
-
-
Exiting the Shell:
- Type
exit
to terminate the shell.
- Type
-
Handling EOF:
-
Test EOF handling by running:
make run < commands.txt
-
Or enter
CTRL-D
at the shell prompt.
-
- Buffer Size: The input buffer size is limited to 187 bytes to prevent overflow.
- Command Parsing: Input strings are parsed into an array of substrings representing the executable and its arguments. This array is passed to
execvp()
. - Piping: The shell supports piping commands using the
|
character, enabling stdout of one command to be redirected as stdin to the next command.
student@student-VirtualBox:~/CSC415/assignment3$ ./assn3 prompt$
prompt$ ls -l
total 20
-rwxr-xr-x 1 student student 13216 Feb 23 13:44 assn3
-rw-r--r-- 1 student student 1583 Feb 23 13:44 assn3.c
Child 2124, exited with 0
prompt$ ls foo
ls: cannot access 'foo': No such file or directory
Child 2125, exited with 2
prompt$ exit
student@student-VirtualBox:~/CSC415/assignment3$
If you would like to contribute to this project, please fork the repository and create a pull request with your changes. Contributions are always welcome!
This project is licensed under the MIT License - see the LICENSE file for details.
- Juan Estrada - Developer of this project.
For support or inquiries, please contact Juan Estrada.