Simple Shell is a custom UNIX command line interpreter implemented in C, developed as part of the Holberton School curriculum. This collaborative project between Raghad Albeladi, Najwa Aljunaidel, and Bushra Alotaibi replicates core functionalities of traditional shells like bash or sh, with a focus on:
- Process Management: Handles command execution using
fork,execve, andwait. - Environment Variables: Supports
envand custom_getenvfor variable lookup. - Built-ins: Implements essential commands like
exitandenv. - Modes: Works in both interactive (user input) and non-interactive (script/file input) modes.
❌ No piping (|) or redirection (>, <).
❌ No advanced features like aliases, job control, or signal handling.
❌ No wildcard expansion (e.g., *.c).
- Language: C (GNU89 standard).
- System Calls:
execve,fork,waitpid,getline, etc. - Testing: Valgrind for memory leaks, Betty for style compliance.
- Task 0. README, man_1_simple_shell, AUTHORS
- Task 1. Betty would be proud
- Task 2. Simple shell 0.1
- Task 3. Simple shell 0.2
- Task 4. Simple shell 0.3
- Task 5. Simple shell 0.4
- Task 6. Simple shell 1.0
- Task 7. What happens when you type ls -l in the shell
Below is a breakdown of the main files in this repository, displayed as badges with descriptions and who implemented each:
-
→ Contains all function prototypes, macros and necessary header includes for our shell. (done with Najwa)
-
→ Implements the REPL loop: reads user input, parses it, and dispatches commands. (done with Najwa)
-
→ Defines a custom
_getenv‑style function to fetch environment variable values. (done with Raghad) -
→ A collection of helper utilities for string handling, memory management and error reporting. (done with Bushra)
-
→ Locates executables on the
$PATHand executes them with the provided arguments. (done with Bushra) -
→ The formatted man‑page for your shell (section 1), describing usage, options and examples. (done with Raghad)
-
→ This file: project Description,Comilation /installation, Requiremnts, Testing and Examples. (done with Raghad)
-
→ Lists all contributors with contact information. (done with Raghad)
A concise list of the core functions and what they do:
| Function | Purpose |
|---|---|
display_prompt(void) |
Print the $ prompt and flush stdout. |
char **split_line(char *line) |
Split an input line on whitespace into a NULL‑terminated array. |
int handle_builtin(char **args, char *line) |
Detect and execute built‑in commands (exit, env, pwd, cd). |
void printenv(void) |
Print all environment variables from environ[]. |
char *my_getenv(const char *name) |
Custom getenv: return the value of name from the environment. |
char *find_path(char *command) |
Search $PATH (or use literal path) for an executable; return full path or NULL. |
int run_exec(char *path, char **args) |
Fork and call execve() on path, wait for child, return its exit status. |
int execute_command(char **args) |
High‑level wrapper: resolve command via find_path and invoke run_exec, handling errors. |
void handle_cd(char **args) |
Implement cd behavior (cd, cd -, default to $HOME, update OLDPWD). |
int main(void) |
Entry point: detect mode, loop on input, dispatch to built‑ins or external commands, clean up. |
- GCC version 9.4.0 or newer (currently using 11.4.0 on Ubuntu 22.04)
- Operating System: Ubuntu 22.04 LTS (sandbox environment)
makeutility (optional but recommended)
The code should be compiled this way:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 -Wno-format *.c -o hshWhat does it do? This command is used to strictly compile all C files in our project. It helps ensure the code is:
✅ Clean and free from common bugs
✅ Following C89 coding standards
✅ Compiled with any warning treated as an error
git clone https://github.com/RaghadAlbeladi1/holbertonschool-simple_shell.git
cd holbertonschool-simple_shellAfter compilation is complete, you're ready to start using the shell.Run
./hshls
pwd
env
exit
You can also press Ctrl + D to exit the shell.$ ./hsh
simple_shell$ echo "Hello, World!"
Hello, World!
simple_shell$ ls -1
AUTHORS
README.md
built-ins.c
execute.c
hbtn_ls
hsh
prompt.c
shell.c
shell.h
tools.c
user_input.c
simple_shell$ exit
$In this session:
- Started the shell with
./hsh - Ran a simple
echocommand - Listed directory contents with
ls -1 - Exited cleanly with
exit
You may only use the following headers, functions and syscalls in your implementation:
All functions from string.h
access (man 2 access)
chdir (man 2 chdir)
close (man 2 close)
closedir (man 3 closedir)
execve (man 2 execve)
exit (man 3 exit)
_exit (man 2 _exit)
fflush (man 3 fflush)
fork (man 2 fork)
free (man 3 free)
getcwd (man 3 getcwd)
getline (man 3 getline)
getpid (man 2 getpid)
isatty (man 3 isatty)
kill (man 2 kill)
malloc (man 3 malloc)
open (man 2 open)
opendir (man 3 opendir)
perror (man 3 perror)
printf (man 3 printf)
fprintf (man 3 fprintf)
vfprintf (man 3 vfprintf)
sprintf (man 3 sprintf)
putchar (man 3 putchar)
read (man 2 read)
readdir (man 3 readdir)
signal (man 2 signal)
stat (man 2 stat) # __xstat
lstat (man 2 lstat) # __lxstat
fstat (man 2 fstat) # __fxstat
strtok (man 3 strtok)
wait (man 2 wait)
waitpid (man 2 waitpid)
wait3 (man 2 wait3)
wait4 (man 2 wait4)
write (man 2 write)
Memory Safety Use Valgrind to verify there are no leaks or invalid accesses:
$ valgrind ./hsh
==12345== Memcheck, a memory error detector
==12345== Command: ./hsh
==12345==
==12345== HEAP SUMMARY:
==12345== in use at exit: 0 bytes in 0 blocks
==12345== total heap usage: 14 allocs, 14 frees, 2600 bytes allocated
==12345==
==12345== All heap blocks were freed -- no leaks are possible
==12345== ERROR SUMMARY: 0 errors
This confirms:
- Every
mallochas a matchingfree. - No invalid reads or writes occurred.
- Your shell cleans up all resources before exiting.


