Welcome to 42sh, our advanced shell interpreter. Designed with a focus on robustness and ease of use, 42sh provides a powerful and intuitive interface for command execution and shell environment management.
- How 42sh Works
- Features
- Monitoring of Shell Variables
- Job Control and Signal Monitoring
- History Management
- Alias Management and Hash Table Interaction
- Check File Types and Compare Values
- Inhibitors
- Conclusion
- Features and Contributors
- Prerequisites
- Installation
- Usage
- Contributing
When a command is entered into 42sh, it undergoes several stages of processing:
Lexical Analysis: Initially, the shell performs a lexical analysis on the input. This phase involves converting a sequence of characters into meaningful sequences, known as lexemes. During this process, 42sh reads the stream of characters that make up the command, grouping them into lexemes. For each lexeme, 42sh generates a token in the form of (token-name, attribute-value), which is then passed on to the next phase—syntactic analysis.
Syntactic Analysis: The subsequent phase is syntactic analysis, also referred to as parsing. In this stage, 42sh utilizes the tokens produced by the lexical analysis to construct a tree-like intermediate representation that illustrates the grammatical structure of the command. This representation is an Abstract Syntax Tree (AST), where each interior node signifies an operation, and the node's children represent the operation's arguments.
Execution: Once the command has been parsed into an AST, 42sh functions as an interpreter to execute the command. An interpreter is a computer program that directly executes instructions written in a programming or scripting language, without the need for these instructions to have been previously compiled into a machine language program. In this context, 42sh interprets the AST and executes the command as per the interpretation.
This README provides an overview of the various capabilities of 42sh, including:
- Shell variable monitoring
- Job control
- History management
- Alias management
- Hash table interaction
- Built-in test operators
42sh is built on top of Mike's and Jakke's 21sh, with each member of the group responsible for one modular part and fulfilling mandatory requirements. This collaboration has resulted in a reliable shell interpreter that caters to the needs of both novice and experienced users.
42sh offers complete monitoring of shell variables, allowing users to:
- Create and export internal variables to the environment using the built-in
export
command.export VAR_NAME="Hello, World!" echo $VAR_NAME # Outputs: Hello, World!
- List all shell internal variables with the
set
command, without any additional options required.set # Lists all shell internal variables.
- Revoke internal and environment variables with the
unset
command.unset VAR_NAME echo $VAR_NAME # Outputs nothing as VAR_NAME is unset.
42sh also supports environment variable creation for unique commands, such as HOME=/tmp cd
, enhancing shell environment management.
42sh provides job control monitoring with built-ins jobs
, fg
, bg
, and the &
operator. The shell interpreter also correctly monitors all signals, ensuring a smooth user experience.
sleep 100 & # Starts a job in the background.
jobs # Lists the jobs.
42sh features complete history management capabilities, allowing users to:
- Access their command history and perform expansions using
!!
,!word
,!number
, and!-number
syntax.echo hello # Outputs: hello !! # Outputs: hello
- Save command history to a file for usage over multiple sessions.
- Perform incremental search in the history with
CTRL-R
.
The built-in fc
command supports all POSIX options.
42sh provides easy alias management with built-ins alias
and unalias
, simplifying the process of creating and removing aliases. Furthermore, 42sh provides a hash table and built-in hash
to interact with it, facilitating the management of frequently used commands.
alias ll="ls -lah" # Creates an alias 'll' for the command 'ls -lah'.
ll # Executes 'ls -lah'.
42sh includes a built-in test
with a comprehensive set of operators, facilitating file type checks and value comparisons.
42sh provides complete handling of inhibitors, including "
(double quote), '
(simple quote) and \
, ensuring that users can execute commands with confidence.
echo "This is a \"quoted\" word." # Outputs: This is a "quoted" word.
42sh is a powerful tool with a comprehensive set of features that allow users to execute commands and manage their shell environment effortlessly. Whether you're a seasoned user or new to the shell environment, 42sh offers a seamless and efficient user experience.
Here, we outline who contributed to each major feature of 42sh:
-
Job Control Monitoring: The 42sh shell includes built-in commands like
jobs
,fg
,bg
, and the&
operator for job control. This feature, contributed by Mike, Jakke, and Max, allows users to manage and monitor processes running in the shell. -
Exit Code Access: Our shell provides the
?$
expansion for accessing the exit status of the last executed command, making error handling more intuitive. This feature is the work of Mike. -
Termcaps Implementation: 42sh supports terminal capabilities (Termcaps) to ensure compatibility with various terminal types. This feature was implemented by Mike and Max.
-
Logical Operators: The shell supports the logical operators "&&" (AND) and "||" (OR) for command chaining and control flow. This feature was contributed by Jakke.
-
Internal Shell Variables Monitoring: The shell tracks the state of internal shell variables, providing the user with useful information about the shell's status. This feature is credited to Miika.
-
Built-in Commands: 42sh includes various built-in commands, such as
cd
,echo
,exit
, andtype
, contributed by Simo. -
POSIX Compliance: Each built-in command conforms to POSIX standards, with exceptions only in explicit cases like
set
orunset
. This adherence to standards was ensured by Simo. -
Inhibitors Handling: The shell properly handles inhibitors, including
"
(double quote),'
(single quote) and\
, allowing users to accurately use these special characters in their commands. This was implemented by Mike. -
Signal Monitoring: 42sh properly handles all signals, ensuring a smooth and safe user experience. This functionality was contributed by Mike.
-
Tilde Expansion and Additional Parameter Formats: The shell supports tilde expansion and various parameter formats for a flexible and user-friendly experience, thanks to Miika.
-
Alias Management: 42sh includes built-ins
alias
andunalias
to easily create and manage command shortcuts. This feature was contributed by Roope. -
Hash Table Interaction: The shell provides a built-in hash table and a
hash
command for interaction, simplifying command execution and storage. This feature is brought to you by Max. -
Built-in
test
Command: The shell includes a built-intest
command with various operators for file type checks and value comparisons, implemented by Max and Jakke. -
History Management: 42sh provides comprehensive history management, including expansions and built-in
fc
with all POSIX options. This was achieved by Max. -
Incremental Search: Users can perform incremental search in the command history using
CTRL-R
, thanks to Mike, 42sh provides an incremental search in the command history using the CTRL-R shortcut, enabling users to find and execute previous commands more efficiently. -
Automated Tester Development: For quality assurance, an automated tester was developed by Jakke, ensuring the shell functions as expected.
Before installing and running 42sh, ensure you have the following:
- A Unix-like operating system (MacOS, Linux, BSD)
- GNU Compiler Collection (GCC) or similar compiler
- GNU make
- Basic knowledge of shell scripting and command-line interfaces
Download the source code:
git clone https://github.com/maxrantil/42sh.git
cd 42sh
Compile and run:
make
./42sh
After compiling the shell, you can start it with the ./42sh command. Here are some examples of how to use 42sh:
# Change directory
cd /path/to/directory
# List files
ls -l
# Use built-in text editor
nano file.txt
For more advanced usage, refer to the GNU Bash Reference Manual.
We welcome contributions from the community. If you'd like to contribute, please follow these steps:
- Fork the repository to your own GitHub account.
- Clone the forked repository to your local machine.
- Make your changes and commit them to your forked repository.
- Submit a pull request with your changes.
Please make sure your code has no syntax errors and is in line with our project's coding style before submitting a pull request.
This shell is designed to prevent crashes (such as segmentation faults or bus issues) and memory leaks. If you encounter any such problems, or if you have suggestions or feedback, please kindly create an issue or PR.