Minishell is a simple, custom shell written in C, designed to emulate the functionality of the bash shell. The project involves handling various processes, file descriptors, and command-line inputs, giving me an opportunity to delve into key concepts related to system programming.
This shell includes support for a command-line interface, pipes, redirections, environment variable handling, and a few built-in commands.
- Displays a command prompt waiting for user input.
- Handles both relative and absolute paths for commands.
- Command history is maintained for easier navigation.
- Supports pipes (|) for passing the output of one command as input to another.
- Redirections:
<
for input redirection.>
for output redirection.<<
reads input until a delimiter is found (here-doc).>>
appends output to an existing file.
- Handles environment variables (
$
) and expands them accordingly. - Recognizes and expands
$?
to the exit status of the most recent command. - Supports signal handling for
ctrl-C
,ctrl-D
, andctrl-\
, behaving similarly to bash. - Built-in commands:
echo
(with-n
option)cd
(with relative or absolute paths)pwd
export
unset
env
exit
- Logical operators
&&
and||
with support for prioritizing execution using parentheses. - Wildcard
*
support for pattern matching in the current directory.
- Clone the repository:
git clone git@github.com:Rui-Pedro-Pires/Minishell.git
- Navigate to the project directory:
cd Minishell
- Compile the project using the provided
Makefile
:make
To start the shell:
./minishell
Once inside the shell, you can execute commands just like in a regular bash terminal.
echo "Hello, World!"
ls -la | grep minishell
cat < input.txt > output.txt
export PATH=/usr/local/bin
- C programming language.
- The
readline
library for command history.
The shell makes use of the following external functions:
readline
,rl_clear_history
,rl_on_new_line
,rl_replace_line
,rl_redisplay
,add_history
- Standard system functions like
printf
,malloc
,free
,write
,fork
,wait
,execve
,dup
,pipe
, and more.