This project consists of creating a simple UNIX command interpreter, similar to /bin/sh, capable of executing commands both in interactive and non-interactive modes.
Here is a flowchart illustrating the internal workflow of the Simple Shell:
- Learning Objectives
- Requirements
- Allowed Functions and System Calls
- Usage
- Installation
- Project Files
- Testing
- GitHub
- Authors
- License
- Understand the history of Unix and its key contributors.
- Know who designed the original Unix operating system and the UNIX shell.
- Discover the B programming language and its creator.
- Understand who Ken Thompson is.
- Learn how a shell works internally.
- Understand process concepts:
pidandppid. - Manage environment variables within a process.
- Distinguish between functions and system calls.
- Create new processes (
fork) and execute programs (execve). - Use the PATH environment variable to locate executable programs.
- Wait for process termination (
wait). - Handle "end-of-file" (EOF) conditions.
- Allowed editors:
vi,vim,emacs - Compilation on Ubuntu 20.04 LTS with:
gcc -Wall -Werror -Wextra -pedantic -std=gnu89
- A
README.mdfile must be present at the root of the project. - Code must follow the Betty coding style.
- No memory leaks are allowed.
- Maximum 5 functions per file.
- Header files must be include guarded.
- Use system calls only when necessary.
You are allowed to use the following C standard functions and system calls:
- Standard C library functions from
string.h access,chdir,close,closedir,execve,exit,_exitfflush,fork,free,getcwd,getline,getpid,isatty,killmalloc,open,opendir,perrorprintf,fprintf,vfprintf,sprintf,putcharread,readdir,signalstat,lstat,fstatstrtok,wait,waitpid,wait3,wait4write
$ ./hsh
($) /bin/ls
file1 file2 shell.c
($) exit
$Execute commands from input without an interactive prompt.
$ echo "/bin/ls" | ./hsh
file1 file2 shell.cRunning multiple commands through a file:
$ cat commands.txt | ./hsh
file1 file2 shell.c
file1 file2 shell.cClone the repository by running the following command:
git clone https://github.com/Roullito/holbertonschool-simple_shell.git
cd your-repo-nameReplace YourUsername/your-repo-name with the actual path to this repository.
We provide a script to automatically install the custom man page for our Simple Shell.
Run the following command:
./install_manpage.shThis will:
- Copy
shell.1to your local man directory (/usr/local/share/man/man1/). - Update the man database.
- Allow you to type
man shellfrom anywhere to access the manual.
Note:
You might need sudo permissions to install the man page, depending on your system configuration.
- Description: Implements the
_memcpyfunction that copies a memory area from one location to another. - Purpose: Used for copying a block of memory from the source to the destination.
- Description: Implements the
_strcpyfunction that copies the string pointed to bysrcto the buffer pointed bydest. - Purpose: Essential for copying strings within the shell's operations.
- Description: Implements the
_strdupfunction that creates a duplicate of a string by allocating new memory. - Purpose: Useful when we need to duplicate strings, particularly for handling environment variables or command arguments.
- Description: Implements the
_strncmpfunction that compares up toncharacters of two strings. - Purpose: A custom comparison function to avoid using the standard
strncmpfor matching strings, often used for commands in the shell.
- Description: Implements the
handle_builtinfunction that manages built-in shell commands likeexit. - Purpose: Allows the shell to execute internal commands directly without needing to invoke an external process.
- Description: Implements the
executefunction, which creates a child process to execute commands. - Purpose: Handles the creation of processes for running commands within the shell.
- Description: Implements the
_whichfunction that finds the full path of a command using thePATHenvironment variable. - Purpose: Determines the location of executable files, helping the shell find and execute commands.
- Description: Implements the
_getlinefunction that reads a line of input from a file descriptor (typicallystdin). - Purpose: Handles user input in the shell, enabling interaction with the program.
- Description: Implements the
mainfunction, which is the entry point of the custom shell. - Purpose: Initializes and runs the shell, managing user input, command parsing, and execution.
- Description: Implements the header file
main.h, which contains all necessary prototypes for the shell's functions. - Purpose: Ensures proper function declaration and code organization throughout the shell program.
- Description: Implements the
_strtokfunction, a custom version of thestrtokfunction used to tokenize strings. - Purpose: Used to break down commands and arguments into tokens for easier processing by the shell.
Your program must replicate the exact behavior of /bin/sh, including error messages.
Error messages must reference the name provided by argv[0].
$ echo "qwerty" | /bin/sh
/bin/sh: 1: qwerty: not found$ echo "qwerty" | ./hsh
./hsh: 1: qwerty: not foundA checker will be provided near the project deadline.
It is strongly recommended to create a full test suite covering both normal and edge cases.
Only one repository per group is allowed.
Forking or cloning another group's repository before the deadline may result in a 0% grade.
🧑💻Authors
Roullito - GitHub
P-Y74 - GitHub
This project is part of the curriculum at Holberton School and is intended for educational purposes only.

