Skip to content

StellaGift/simple_shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Shell

Overview

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.

Features

  • 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, and unsetenv.
  • Environment Variables: Provides functions to handle environment variables, including setting, unsetting, and printing.
  • Path Resolution: Resolves the full path of the command using the PATH environment variable.
  • Error Handling: Includes error handling for various scenarios, such as command not found and invalid input.

Usage

  1. Compilation: Compile the program using a C compiler, for example:

    gcc -o simple_shell simple_shell.c
  2. Execution: Run the compiled program:

    ./simple_shell
  3. Command Input: Enter commands in the shell prompt, and press Enter to execute.

Built-in Commands

  • 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

Path Resolution

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.

Error Handling

The shell provides informative error messages for various scenarios, such as command not found, invalid input for setenv and unsetenv, and general execution errors.

Examples

  1. Execute Command:

    $ ls
  2. Set Environment Variable:

    $ setenv MY_VARIABLE my_value
  3. Unset Environment Variable:

    $ unsetenv MY_VARIABLE
  4. Exit the Shell:

    $ exit

Notes

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages