Skip to main content

Starting Minishell

To start Minishell, simply run the executable:
./minishell
You’ll be greeted with a welcome banner and the interactive prompt:
==== Welcome to minishell by Ibon & Iker ====
A minimal shell implementation | 42 School Project

███╗   ███╗██╗███╗   ██╗██╗██╗██╗██╗
████╗ ████║██║████╗  ██║██║██║██║██║
██╔████╔██║██║██╔██╗ ██║██║██║██║██║
██║╚██╔╝██║██║██║╚██╗██║██║██║██║██║
██║ ╚═╝ ██║██║██║ ╚████║██║██║██║██║
╚═╝     ╚═╝╚═╝╚═╝  ╚═══╝╚═╝╚═╝╚═╝╚═╝

Understanding the Prompt

The Minishell prompt shows your username and current directory:
username/home/user/current/directory-> 
The prompt is dynamically generated and updates when you change directories.

Command Line Syntax

Minishell accepts commands in the following format:
command [options] [arguments]
1

Enter a command

Type your command at the prompt:
username/home/user-> ls -la
2

Press Enter

Press Enter to execute the command. Minishell will parse and execute it.
3

View results

The output appears below your command, and a new prompt is displayed.

Command History

Minishell uses the GNU Readline library, providing powerful command history features:
  • Up Arrow (↑): Navigate to previous commands
  • Down Arrow (↓): Navigate to next commands in history
  • Ctrl+R: Search through command history (reverse search)
All commands you enter are automatically saved to history, allowing you to easily recall and re-execute previous commands.

Quote Handling

Minishell supports both single and double quotes with different behaviors:

Single Quotes (')

Single quotes preserve the literal value of all characters within the quotes:
echo 'Hello $USER'
# Output: Hello $USER

Double Quotes (")

Double quotes preserve the literal value of most characters, but allow variable expansion:
echo "Hello $USER"
# Output: Hello john
Unclosed quotes will result in a syntax error. Make sure to close all quote pairs:
echo "hello world  # Error: unclosed quotes
echo "hello world"  # Correct

Special Characters

Minishell recognizes several special characters:
CharacterMeaningExample
$Variable expansionecho $HOME
``Pipe operator`lsgrep txt`
<Input redirectioncat < file.txt
>Output redirectionecho hi > out.txt
>>Append redirectionecho hi >> out.txt
<<Heredoccat << EOF

Variable Expansion

Minishell expands environment variables prefixed with $:
# Standard variable expansion
echo $HOME
# Output: /home/user

# Special variables
echo $?      # Exit status of last command
echo $$      # Process ID of current shell
echo $0      # Name of the shell (outputs: Minishell)
Variable expansion does not occur inside single quotes, but does occur inside double quotes.

Common Usage Patterns

Combining Commands

Use pipes to chain multiple commands:
ls -l | grep .txt | wc -l

Redirecting Output

Save command output to a file:
ls -la > directory_listing.txt

Reading from Files

Provide file content as input:
wc -l < input.txt

Exiting Minishell

There are two ways to exit Minishell:
1

Using the exit command

Type exit to close the shell:
exit
# Or with an exit code
exit 42
2

Using Ctrl+D

Press Ctrl+D (EOF) to exit immediately.
When you exit, Minishell displays a red “Exit” message to confirm termination.

Signal Handling

Minishell handles common signals:
  • Ctrl+C (SIGINT): Interrupts the current command and displays a new prompt
  • Ctrl+\ (SIGQUIT): Ignored (does nothing)
  • Ctrl+D (EOF): Exits the shell when entered on an empty line
Ctrl+C sets the exit status to 130, which you can check with echo $?

Error Handling

When errors occur, Minishell provides helpful messages:
# Command not found
unknowncommand
# Output: unknowncommand : command not found

# Syntax errors
ls | | grep
# Output: syntax error: pipes

# Invalid redirections
cat < nonexistent.txt
# Output: nonexistent.txt : No such file or directory
The exit status is stored in $? and can be checked:
ls nonexistent
echo $?
# Output: 1 (error code)

Build docs developers (and LLMs) love