A simple Unix-like shell implementation using Lex/Flex and Yacc/Bison.
To build the minishell executable, run:
makeThis will:
- Generate the parser from
shell.yusing Bison - Generate the scanner from
shell.lusing Flex - Compile all sources into the
minishellexecutable
After building, run the shell with:
./minishellYou will see the minishell> prompt where you can enter commands.
- Execute external programs with arguments
- Uses
PATHenvironment variable to locate executables - Example:
ls -l /tmp
- cd [dir]: Change directory
- pwd: Print working directory
- exit: Exit the shell
- Variable expansion using
$VARsyntax - Variable assignment using
NAME=value - Example:
echo $HOME
- Input redirection:
cmd < file - Output redirection:
cmd > file - Append redirection:
cmd >> file - Example:
cat < input.txt > output.txt
- Single pipeline support:
cmd1 | cmd2 - Example:
ls -l | grep txt
- Run commands in background using
& - Example:
sleep 10 &
- Lines starting with
#are treated as comments
- Support for double quotes:
"string with spaces" - Support for single quotes:
'another string'
# Simple commands
SlimHady'sShell> ls -la
SlimHady'sShell> pwd
SlimHady'sShell> cd /tmp
# Environment variables
SlimHady'sShell> HOME=/home/user
SlimHady'sShell> echo $HOME
# Redirection
SlimHady'sShell> cat file.txt > output.txt
SlimHady'sShell> cat >> output.txt < input.txt
# Pipelines
SlimHady'sShell> ls -l | grep .txt
SlimHady'sShell> cat file.txt | wc -l
# Background execution
SlimHady'sShell> sleep 5 &
# Exit the shell
SlimHady'sShell> exit- Only single pipelines are supported (not multiple pipes like
cmd1 | cmd2 | cmd3) - No support for complex shell features like:
- Command substitution
- Wildcards/globbing
- Job control (fg, bg, jobs)
- Signal handling (Ctrl-C)
- History
- Tab completion
The shell handles various error conditions:
- Invalid commands display "command not found"
- Failed directory changes display appropriate error messages
- Invalid file redirections display error messages
- Syntax errors are caught and the shell continues running
To remove all generated files and the executable:
make cleanshell.l: Lex scanner specificationshell.y: Yacc parser specification with execution logicMakefile: Build configurationREADME.md: This file
- GCC compiler
- Flex (or Lex)
- Bison (or Yacc)
- POSIX-compliant system (Linux recommended)