Minishell is a project designed to create a simple, custom shell in C, closely mimicking the functionality of Bash. The project focuses on understanding processes, file descriptors, and various shell operations. This README provides a detailed guide on the structure, functionality, and usage of the Minishell project.
The existence of shells is linked to the very existence of IT. Initially, developers used aligned 1/0 switches to communicate with computers, which was quite cumbersome. The invention of shells allowed interactive command-line communication in a language closer to human language. With Minishell, we revisit the fundamental problems faced before modern GUIs and sophisticated shells like Bash.
Minishell includes the following features:
- Display a prompt while waiting for a new command.
- Maintain a working history of commands.
- Search and execute the correct executable based on the PATH variable or using a relative/absolute path.
- Handle single and double quotes to manage metacharacters.
- Implement input (
<
), output (>
), append (>>
), and here-document (<<
) redirections. - Support pipes (
|
) to connect the output of one command to the input of another. - Manage environment variables and special parameter
$?
for the exit status of the most recently executed foreground pipeline. - Handle
ctrl-C
,ctrl-D
, andctrl-\
signals as in Bash. - Built-in commands:
echo
,cd
,pwd
,export
,unset
,env
, andexit
.
To install and run Minishell, follow these steps:
-
Clone the Repository
git clone <repository-url> cd minishell
-
Build the Project
make
-
Run Minishell
./minishell
Once Minishell is running, you can use it similarly to Bash:
-
Basic Commands
ls -l echo "Hello, World!"
-
Redirections
cat < input.txt echo "New content" > output.txt echo "Append this" >> output.txt cat << EOF > This is a > here-document example > EOF
-
Pipes
ls -l | grep minishell
-
Environment Variables
echo $HOME echo $?
-
Signal Handling
ctrl-C
: Displays a new prompt on a new line.ctrl-D
: Exits the shell.ctrl-\
: Does nothing.
Minishell implements several built-in commands:
-
echo
echo -n "No newline"
-
cd
cd /path/to/directory
-
pwd
pwd
-
export
export VAR=value
-
unset
unset VAR
-
env
env
-
exit
exit