This is a basic implementation of a shell in C++. It provides a command-line interface with several built-in commands and the ability to execute external programs.
The shell implements a Read-Eval-Print Loop (REPL) that:
- Displays a prompt
- Reads user input
- Parses the input into a command and arguments
- Executes the command
- Repeats
Built-in commands are handled directly by the shell, while external commands are executed by searching the system PATH.
To build the shell, you'll need:
- A C++ compiler supporting C++17 (e.g., GCC 7+ or Clang 5+)
- The standard C++ library
Follow these steps to build the shell:
g++ -std=c++17 main.cpp -o simple_shell
This will create an executable named main in the current directory.
To run the shell:
- Open a terminal
- Navigate to the directory containing the
simple_shellexecutable - Run the following command:
./main
You should now see the shell prompt $, indicating that the shell is ready to accept commands.
ALTERNATIVELY,
You can build and run the shell by executing,
./your_shell.sh
This will build and run the executable and you will see the shell prompt $, indicating that the shell is ready to accept commands.
To run this step you should have vcpkg ececutable installed, and you should clone the vcpkg repository and save its path as the environment variable VCPKG_ROOT.
The shell supports the following built-in commands:
okay: Prints "All okay!"exit [status]: Exits the shell with the provided status codeecho [args...]: Prints the provided argumentstype [command]: Identifies whether a command is a shell builtin or an external programpwd: Prints the current working directorycd [directory]: Changes the current working directory
In addition to these built-in commands, the shell can execute any external programs available in the system PATH.
$ okay
All okay!
$ echo Hello, World!
Hello, World!
$ pwd
/home/user/current/directory
$ cd ..
$ pwd
/home/user/current
$ type echo
echo is a shell builtin
$ type ls
ls is /bin/ls
$ ls
file1.txt file2.txt directory1
$ exit 0
Note: The actual output may vary depending on your system configuration and current directory contents.
Caution: Some parts of this readme were genrated by an LLM, others were written by a human.