The shell is a program that facilitates interaction with the operating system by accepting commands from the user through the terminal. It acts as an interface, forwarding user inputs to the operating system for execution.
This project represents a custom shell, named simple_shell, developed for Holberton School as part of the "Low-level programming & Algorithm - Linux and Unix system programming" curriculum. Implemented in the C programming language, this shell introduces additional functionalities beyond a standard shell.
- Displays a custom prompt "#Kiro$ " when in interactive mode.
- Supports executing commands with arguments and handling absolute paths.
- Handles built-in commands such as "exit" and "env."
- Provides dynamic path resolution using the PATH environment variable.
- Manages signals such as Ctrl + C gracefully, preventing accidental shell termination.
-
command_exe.c:
printerror
: Prints an error message when a command is not found.execute_com
: Forks a new process to execute a command usingexecve
.ex_com
: Determines the path and returns the exit status of a command.
-
get_path_env.c:
find_env_key
: Finds the value of an environment variable based on the key._getenv
: Gets the value of an environment variable using the key.is_absolute_path
: Checks if a command is an absolute path.search_in_path
: Searches for a command in the directories specified by the PATH variable._getpath
: Determines the path of a command, considering both absolute and relative paths.
-
king.c:
main
: The main function serving as the entry point for the custom shell.read_com
: Reads the user input for a command line.print_env
: Prints environment variables._putchar
: Writes a string to standard output.
-
simple_shell.h:
- Header file containing function prototypes and necessary includes.
-
read_b_env.c:
read_com
: Reads the user input for a command line.print_env
: Prints environment variables._putchar
: Writes a string to standard output.
-
strings_3.c:
_strdup
: Duplicates a string._strcmp
: Compares two strings._strlen
: Returns the length of a string._strcat
: Concatenates two strings._strcpy
: Copies a string.
-
tools_3.c:
reverse_str
: Reverses a string._itoa
: Converts an integer to a string.freearray
: Frees a dynamically allocated array of strings.get_com_path
: Gets the path of the input command.
The development of this custom shell adheres to the following list of allowed functions and system calls:
-
File System Manipulation:
-
Process Execution:
-
Input/Output:
-
Memory Management:
-
Directory Handling:
-
Signal Handling:
-
Process Termination:
-
File Operations:
-
String Manipulation:
strtok
(man 3 strtok)
-
Miscellaneous:
For detailed information about each function or system call, refer to the provided man pages.
To experience our custom shell, follow these steps:
- Clone our repository using the command (ensure Git is installed):
git clone https://github.com/kirolloushany03/simple_shell
- Change directory to simple_shell:
cd simple_shell
- Compile the C files:
gcc -Wall -Werror -Wextra -pedantic *.c -o myshellk
- Run the shell:
./myshellk
When exiting the shell, use one of the following methods:
- Type the command "exit":
exit
- Press Ctrl + D.