- Introduction
- Features
- Installation
- How to use
- Built-in Commands
- Code Organization
- Requirements
- Contact
- License
This is a comprehensive and efficient implementation of a simple shell program. The shell, named "Simple Shell," provides a user-friendly command-line interface to interact with the operating system. It supports basic command execution, environment variables, aliases, and other essential shell functionalities.
-
Command Execution: Simple Shell allows users to execute various commands with arguments, just like a standard shell(e.g.,
ls,cat,mkdir, etc.) . -
Environment Variables: Users can manage environment variables and access their values within the shell.
-
Aliases: Simple Shell supports user-defined aliases for frequently used commands or command combinations.
-
Input Redirection: The shell allows users to redirect standard input from files, enabling them to read commands from external sources.
-
Output Redirection: Users can redirect standard output to files, enabling them to save command output to external files.
-
Piping: Simple Shell supports command chaining with pipes, allowing users to send the output of one command as input to another command.
-
Interactive and Batch Modes: The shell operates in interactive mode, providing an intuitive command prompt. Additionally, it can also execute commands from batch files in non-interactive mode.
-
Error Handling: Proper error handling is implemented throughout the code to ensure graceful handling of unexpected scenarios.
-
Efficient Data Structures: Simple Shell uses linked lists and dynamic memory allocation for efficient handling of data structures.
-
Handle arguments for the built-in
exitcommand to exit the shell with a specific status.
To use the Simple Shell, follow these steps:
- Clone the repository to your local machine:
git clone https://github.com/ebuka1017/simple_shell
- Compile the source code using a C compiler (e.g.,
gcc):
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 *.c -o hsh
- Run the shell:
./hsh
Once the Simple Shell is running, you can enter commands as you would in a regular shell. The shell will display the prompt, and you can start entering commands:
$ ls
file1.txt file2.txtTo execute the built-in exit command with a specific status, use the following format:
$ exit status
Replace status with an integer that will be used to exit the shell. If no argument is provided, the shell will exit with status 0.
To execute commands from a batch file, provide the file as an argument to the shell:
./simple_shell batch_commands.txtTo Initialize a new environment variable or set a new one.
$ setenv VARIABLE VALUETo remove an environment variable:
$ unsetenv VARIABLEThe Simple Shell includes the following built-in commands:
cd [directory]: Change the current working directory todirectory. If no argument is provided, change to the home directory.env: Display the current environment variables.exit [status]: Exit the shell with the specifiedstatus. If no argument is provided, exit with status 0.setenv & unsetenv: initialize or modify a(n) environment variable && remove an environment variable
The Simple Shell codebase is organized into multiple source files, each serving a specific purpose:
-
main.c: Contains the main function to initiate the shell. -
shell.c: Implements the core functionalities of the shell, such as command execution and processing. -
input.candinput_func.c: Handle user input and read commands from standard input or batch files. -
execute.c: Executes commands and handles built-in commands. -
file_info.c,file_io_func.c, andmem_func.c: Manage file and memory-related functionalities. -
func_hsh.c,my_chain.c,my_path.c, andprompt.c: Implement various utility functions required by the shell. -
env_func1.candenv_func2.c: Provide functionality for managing environment variables. -
alias_func.c: Implement alias-related functions. -
err_func.canderr_func2.c: Handle error reporting and error handling. -
str_func1.c,str_func2.c, andstr_func3.c: Contain string manipulation functions used throughout the shell. -
linked_list1.candlinked_list2.c: Implement linked list data structure and related functions. -
emulator_func.candutils.c: Contain additional utility functions used by the shell. -
utils2.c: Houses more utility functions used in the shell.
The Simple Shell program has been developed and tested on various Unix-like systems, including Linux and macOS. It requires a standard C compiler (GCC) and a POSIX-compliant operating system.
For any questions or suggestions, feel free to reach out to us at [email protected].
Authors: ebuka1017, Omarr-kh
Organization: alx_africa
Date: July, 2023
The Simple Shell is open-source software released under the MIT License. Feel free to use, modify, and distribute the code as permitted by the license.
