This is a simple shell program written in C that provides a basic command-line interface. The shell supports various functionalities such as executing commands, managing environment variables, and printing the environment.
- Command Execution: Allows the user to execute commands provided through the command line.
- Built-in Commands: Supports built-in commands such as
exit,env,setenv, andunsetenv. - Environment Variables: Provides functions to handle environment variables, including setting, unsetting, and printing.
- Path Resolution: Resolves the full path of the command using the
PATHenvironment variable. - Error Handling: Includes error handling for various scenarios, such as command not found and invalid input.
-
Compilation: Compile the program using a C compiler, for example:
gcc -o simple_shell simple_shell.c
-
Execution: Run the compiled program:
./simple_shell
-
Command Input: Enter commands in the shell prompt, and press Enter to execute.
- exit: Exits the shell.
- env: Displays the current environment variables.
- setenv: Sets a new environment variable or modifies an existing one.
setenv VARIABLE VALUE
- unsetenv: Unsets (removes) an environment variable.
unsetenv VARIABLE
The shell resolves the full path of the entered command using the PATH environment variable. If the command is not found in the current directory, the shell searches through the directories specified in the PATH variable.
The shell provides informative error messages for various scenarios, such as command not found, invalid input for setenv and unsetenv, and general execution errors.
-
Execute Command:
$ ls
-
Set Environment Variable:
$ setenv MY_VARIABLE my_value
-
Unset Environment Variable:
$ unsetenv MY_VARIABLE
-
Exit the Shell:
$ exit
- The shell supports basic functionalities and may not cover all edge cases or advanced features found in fully-featured shells.
- This implementation focuses on simplicity, usage flexibility and ease of understanding.
Program is fully scalable and customizable to suit per case needs.