This program is a simple Unix shell implemented in C using the gnu89 standard.
The purpose of this project was to demonstrate our (Bezaleel Olakunori & Elmahdi Mamoun) understanding of a variety of programming concepts and low-level system functionalities.
Here's a screenshot of our simple shell in action.
Run the command below to build the shell.
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o simple_shellAfter compiling the program, run ./simple_shell to startup the shell in interactive mode. To start the shell in non-interactive mode, run ./simple_shell file, where file is a text-encoded file containing lines of commands to be executed. You can also pipe a string of commands to the program like echo 'echo $PWD' | ./simple_shell to be run in a non-interactive mode.
| Operator | Description |
|---|---|
| ; | Separates commands into command lists that can be executed unconditionally (doesn't depend on the failure or success of the previous command) |
| && | Executes the next command in a command list if the previous command succeeded (had an exit code of 0) |
| || | Executes the next command in a command list if the previous command failed (had a non-zero exit code) |
- Command: alias
Usage:alias [name[='value'] ...]
Description: Prints a list of aliases when no arguments are provided. If a name is provided in the arguments, it prints the alias' value in the formname='value'. If a name-value pair is provided, it creates or assigns an alias (name) with the value value. This only happens in the interactive mode. - Command: cd
Usage:cd [DIRECTORY]
Description: Changes the shell's current working directory to DIRECTORY if it is provided. If DIRECTORY is -, it switches the current working directory (PWD) with the previous working directory (OLDPWD). If DIRECTORY is not provided, the current working directory is changed to the home directory. - Command: env
Usage:env
Description: Prints the list of environment variables. - Command: exit
Usage:exit status
Description: Exits the shell with status code status (ranges from 0 to 255 inclusive) or the status code of the last command that was executed. - Command: help
Usage:help
Description: Prints the help page of a built-in command or the program. - Command: history
Usage:history
Description: Prints the list of commands that have been stored by the shell. - Command: setenv
Usage:setenv VARIABLE VALUE
Description: Sets the value of an environment variable named VARIABLE to VALUE. - Command: unsetenv
Usage:unsetenv VARIABLE
Description: Removes an environment variable named VARIABLE.
Install GCC on your system.
Load the bash script into your BASH terminal using source .bashrc. This would enable the following functions to be used:
build- Builds the programbuild_dbg- Creates a debugging build of the programrun- Runs the built version of the programinstall- Installs the built version of the programval- Launches the program with Valgrind (should be used after build_dbg)viewman- Opens the man page for the program
You can find the test suite here.
