Skip to content

msh is a custom, lightweight shell program written in the C programming language. It provides users with a command-line interface (CLI) to execute various system commands, manage processes, and interact with the operating system in a controlled environment.

Notifications You must be signed in to change notification settings

MohakGupta2004/msh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 

Repository files navigation

msh (Simple Shell)

msh is a simple shell program implemented in C that handles basic built-in commands such as echo, exit, and type, along with the ability to execute external commands by searching for them in the system's PATH. The shell supports command-line parsing, forking processes, and executing commands.

Features

  • Built-in Commands:

    • echo: Prints arguments to the terminal.
    • exit: Exits the shell.
    • type: Displays the type (built-in or path) of the given command.
  • External Command Execution:

    • Executes external commands by searching for them in the system's PATH.
    • Forks a child process to execute commands.

Compilation

To run the program, use the following make command:

make run

To compile the program, use the following gcc command:

gcc -o msh main.c

This will produce an executable file named msh.

Usage

After compiling the program, you can run the shell by executing the following command in your terminal:

./msh

This will start the interactive shell prompt, where you can type commands.

Available Commands

  1. echo <text>:

    • Prints the provided text to the console.

    Example:

    $ echo Hello World
    Hello World
  2. exit:

    • Exits the shell.

    Example:

    $ exit
  3. type <command>:

    • Displays the type of the command (builtin or path to the executable).

    Example:

    $ type ls
    ls is /bin/ls
  4. External Commands:

    • Any other command is treated as an external command. The shell will search for the command in the directories listed in the PATH environment variable and execute it if found.

    Example:

    $ ls

Error Handling

  • If a command is not found, the shell will display an error message:

    $ nonexistent_command
    nonexistent_command: command not found
  • If the type command is used without any arguments:

    $ type
    type: missing operand

License

This project is licensed under the MIT License.

Contributing

Feel free to fork this repository and submit pull requests with improvements or bug fixes!

About

msh is a custom, lightweight shell program written in the C programming language. It provides users with a command-line interface (CLI) to execute various system commands, manage processes, and interact with the operating system in a controlled environment.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published