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.
-
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.
- Executes external commands by searching for them in the system's
To run the program, use the following make command:
make runTo compile the program, use the following gcc command:
gcc -o msh main.cThis will produce an executable file named msh.
After compiling the program, you can run the shell by executing the following command in your terminal:
./mshThis will start the interactive shell prompt, where you can type commands.
-
echo <text>:- Prints the provided text to the console.
Example:
$ echo Hello World Hello World -
exit:- Exits the shell.
Example:
$ exit -
type <command>:- Displays the type of the command (
builtinor path to the executable).
Example:
$ type ls ls is /bin/ls - Displays the type of the command (
-
External Commands:
- Any other command is treated as an external command. The shell will search for the command in the directories listed in the
PATHenvironment variable and execute it if found.
Example:
$ ls
- Any other command is treated as an external command. The shell will search for the command in the directories listed in the
-
If a command is not found, the shell will display an error message:
$ nonexistent_command nonexistent_command: command not found -
If the
typecommand is used without any arguments:$ type type: missing operand
This project is licensed under the MIT License.
Feel free to fork this repository and submit pull requests with improvements or bug fixes!