Paintballskaguy / atlas-simple_shell

0 stars 0 forks source link



Atlas-simple_shell 🐢🍕

Description

Atlas-simple_shell is a basic terminal shell that allows users to interact with the file system and execute commands. Inspired by the Teenage Mutant Ninja Turtles, it provides a simple command-line interface for listing commands and files, making it easy to navigate your computer's directory like a ninja in the sewers of New York City.

Installation

To build and use Atlas-simple_shell, follow these steps:

  1. Clone the repository:
    git clone https://github.com/yourusername/atlas-simple_shell.git
    cd atlas-simple_shell
gcc -Wall -Werror -Wextra -pedantic -std=gnu89 main.c prompt.c execute.c -o hsh 

Usage

Copy code
./hsh

Interactive Mode

Copy code
$ ./hsh
($) /bin/ls
hsh main.c shell.c
($)
($) exit
$

Non-Interactive Mode

You can also use the shell in non-interactive mode by piping commands to it:

Copy code
echo "/bin/ls" | ./hsh
hsh main.c shell.c

Or by redirecting input from a file:

Copy code
$ cat test_ls_2
/bin/ls
/bin/ls
$ cat test_ls_2 | ./hsh
hsh main.c shell.c
hsh main.c shell.c

How It Works

Interactive Mode: When you run ./hsh, it starts in interactive mode, displaying the ($) prompt. You can type commands directly and see the output.

Non-Interactive Mode: When commands are piped into ./hsh, it reads and executes them without displaying the prompt.

Features

Steps Explained in Simple Terms

  1. Start the Program: Begin running the shell.
  2. Set up Initial Values: Prepare some initial settings and variables.
  3. Show a Prompt: Display a prompt (like "$") and wait for the user to type something.
  4. User Types Something?: Check if the user has typed something and pressed Enter.
  5. If No Input: If the user didn't type anything, end the program.
  6. Clean the Input: If the user typed something, remove any unnecessary spaces.
  7. Is Input Empty?: Check if the cleaned input is empty.
  8. If Input is Empty: If the input is empty, wait for the user to type again.
  9. If Input is "Exit": If the user typed "exit," stop the program.
  10. Check for "Env": If the input is not "exit," check if the user typed "env."
  11. Show Environment Settings: If the user typed "env," display all environment settings.
  12. Wait for New Input: Wait for the user to type something new.
  13. Break Input into Parts: If the user typed something else, break the input into parts (words).
  14. Run the Command: Execute the command the user typed and show the result.
  15. Clean Up: Clean up and prepare to repeat the process.
  16. Loop Back: Go back to showing the prompt and waiting for new input.

    Examples

    Here are some example commands you can run in Atlas-simple_shell:

Copy code
($) /bin/pwd
/home/username/atlas-simple_shell
($) /bin/echo "Cowabunga!"
Cowabunga!
($) /bin/ls -l
total 24
-rw-r--r-- 1 username username 1234 Jul 23 12:34 main.c
-rw-r--r-- 1 username username 5678 Jul 23 12:34 prompt.c
-rw-r--r-- 1 username username 9101 Jul 23 12:34 execute.c
($) exit

Built-in Commands

The following built-in commands are available in Atlas-simple_shell:

Acknowledgments

Teenage Mutant Ninja Turtles: For their endless inspiration. Open-source community: For their invaluable resources and support. You: For using and contributing to Atlas-simple_shell. Cowabunga, dude! 🐢🍕

Authors