Minishell is a custom-built shell that replicates essential functionalities of a Unix shell environment. This project serves as a minimalistic shell interpreter with core features to handle command execution, redirections, pipes, environment variable management, and built-in commands. The shell is designed to offer an interactive command-line interface with a focus on simplicity and efficiency.
- Command Prompt: Displays a prompt for user input when waiting for new commands.
- Command History: Maintains a history of previously executed commands.
- Executable Search: Searches for and executes commands based on the
PATH
variable or a provided relative/absolute path. - Signal Handling: Utilizes a single global variable to handle signals, ensuring the signal handler does not access the main data structures.
- Quoting:
- Handles single quotes (
'
) to prevent interpretation of meta-characters within quoted sequences. - Handles double quotes (
"
) to prevent interpretation of meta-characters, except for dollar signs ($
).
- Handles single quotes (
- Redirections:
<
redirects input.>
redirects output.<<
reads input until a delimiter line is encountered (does not update history).>>
appends output to an existing file.
- Pipes: Connects the output of one command to the input of the next command using pipes (
|
). - Environment Variables:
- Expands environment variables (
$
) to their values. - Expands
$?
to the exit status of the most recently executed foreground pipeline.
- Expands environment variables (
- Signal Handling:
Ctrl-C
displays a new prompt on a new line.Ctrl-D
exits the shell.Ctrl-\
does nothing.
- Built-in Commands:
echo -n
: Outputs text without a trailing newline.cd
: Changes the current directory (supports relative and absolute paths).pwd
: Prints the current working directory.export
: Sets environment variables (no options).unset
: Removes environment variables (no options).env
: Displays environment variables (no options or arguments).exit
: Exits the shell (no options).
- Signal Handling: Uses a single global variable to capture signal numbers, avoiding direct manipulation of main data structures within the signal handler.
- Memory Management: The
readline()
function, used for command input, may cause memory leaks, which are not fixed in this implementation. However, the shell’s own code is managed to avoid memory leaks.
-
Clone the Repository:
git clone <repository-url>
-
Compile the Project:
make
-
Run the Shell:
./minishell
- Command Execution: Type commands at the prompt and press Enter.
- Redirections: Use
<
,>
,<<
, and>>
to manage input and output redirections. - Pipes: Connect commands using
|
. - Built-ins: Utilize the implemented built-in commands for various shell functionalities.
- The 42 School for providing the project specifications and environment.