Welcome to Bashy, a custom shell implementation designed to mimic the behavior of the Bash shell. This project serves as a practical exercise in understanding shell mechanics, process management, and command execution in Unix-like operating systems.
- Features
- Getting Started
- Prerequisites
- Installation
- Usage
- Commands Implemented
- Environment Variables
- Error Handling
- Contributing
- License
- Command Execution: Execute a variety of shell commands, including built-in commands and external binaries.
- Piping and Redirection: Support for piping (
|) and redirection (>,<) to manipulate input and output streams. - Built-in Commands: Includes essential commands such as
cd,echo,exit,env, andexport, with full functionality. - Signal Handling: Proper handling of Unix signals (like
SIGINTandSIGQUIT) for a responsive user experience. - Environment Management: Maintain and manipulate environment variables seamlessly.
- Customizable: Easily extendable to add new features and commands.
To get started with Bashy, clone the repository and compile the source code.
Before installing and running Bashy, ensure that you have the necessary dependencies installed.
-
Readline Library: Bashy depends on the Readline library for command-line input handling. You can install it using
brew:brew install readline
-
After installing
readline, update the Makefile to point to the correct paths. Modify the following lines in the Makefile:# Paths for the Readline library READLINE_L = ~/.brew/opt/readline/lib READLINE_I = ~/.brew/opt/readline/include
- Clone the repository:
git clone <repository-url> cd minishell
- Compile the source code:
make
- Run the shell:
./minishell
Once you launch Bashy, you will see a prompt where you can enter your commands. Simply type your command and press Enter. The shell will execute the command and display the output.
- Example Commands:
echo "Hello, World!" # Outputs: Hello, World!
cd /path/to/directory # Change current directory
ls -la # List files in the current directory
export MY_VAR="Value" # Set an environment variable
env # Display environment variablesBashy supports a variety of built-in commands:
-
cd [path]: Change the current directory.
-
echo [string]: Print the specified string to the standard output.
-
exit [status]: Exit the shell with the specified status.
-
env: Display the current environment variables.
-
export [variable=value]: Set or update environment variables.
-
unset [variable]: Remove environment variables.
Bashy allows you to manage environment variables using the export and unset commands. You can check the current environment variables using the env command.
- Example Usage:
export MY_VAR="Hello" # Set environment variable
echo $MY_VAR # Outputs: Hello
unset MY_VAR # Remove environment variableBashy provides comprehensive error handling for various scenarios, including:
-
Invalid commands
-
Incorrect usage of built-in commands
-
Errors during file operations (e.g., redirection failures)
-
Error messages are displayed to the user to aid in debugging.
Contributions are welcome! If you have suggestions for improvements or new features, please fork the repository and submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.