A lightweight Unix shell implementation in C that provides essential command-line functionality including built-in commands, program execution, environment variable management, and alias support.
-
Built-in Commands
cd [dir]- Change the working directoryexit [STATUS]- Exit the shell with optional status codeenv- Display environment variablessetenv VARIABLE VALUE- Set or modify an environment variableunsetenv VARIABLE- Remove an environment variablehelp [BUILTIN_NAME]- Display help informationalias [name='value']- Create, display, or modify aliases
-
External Program Execution
- Forks child processes to execute external commands
- Searches PATH for executables
- Properly handles exit codes and signals
-
Additional Features
- Interactive mode with prompt (
dali<3) - Non-interactive mode for reading commands from files
- Signal handling (Ctrl+C)
- Variable expansion (
$VAR) - Alias expansion
- Error reporting and status codes
- Interactive mode with prompt (
Compile the shell with gcc:
gcc -o simple_shell *.cRun the shell and start typing commands:
./simple_shell
dali<3 ls -l
dali<3 cd /home
dali<3 exitExecute commands from a file:
./simple_shell commands.txt# Change directory
dali<3 cd /tmp
# List files (external command)
dali<3 ls -la
# Set environment variable
dali<3 setenv MYVAR "hello world"
# Display environment
dali<3 env
# Create an alias
dali<3 alias ll="ls -la"
# Use the alias
dali<3 ll
# Get help
dali<3 help cd
dali<3 help
# Exit with status
dali<3 exit 0main.c- Entry point and main loopexec.c- Command execution using fork/execvebuiltin.c- Built-in commands (env, setenv, unsetenv, exit, alias)more_builtin.c- Additional built-in commands (cd, help)env_manage.c- Environment variable managementalias_manage.c- Alias managementtokensize.c- Input tokenizationstrtok.c- String tokenization_getline.c- Input line readinghelpers.c- String utility functionsmore_helpers.c- Additional helper functionseven_more_helpers.c- More helper functionsfin_paths.c- Path resolutionexp.c- Variable and alias expansionshell.h- Header file with structures and function declarationsmacro.h- Macros for messages and configuration
- Uses fork() and execve() for process creation
- Maintains its own copy of the environment variables
- Uses a custom data structure (
data_of_program) to track program state - Handles signals gracefully (Ctrl+C displays a new prompt)
- Supports chaining commands via logic operators
- Implements custom string functions to avoid libc dependencies where possible
This project is provided as-is for educational purposes.