This is a simple shell emulator implemented in Python. It supports a few basic shell commands including exit
, echo
, type
, pwd
, and cd
.
- exit: Exit the shell. The command
exit 0
will successfully exit the shell. - echo: Print the provided arguments to the standard output.
- type: Determine if a command is a shell builtin or an external command.
- pwd: Print the current working directory.
- cd: Change the current working directory. Supports the
~
symbol to navigate to the home directory.
- Python 3.x
- An operating system that supports the standard Unix-like shell commands.
-
Clone the repository or download the script file.
-
Ensure you have Python 3.x installed on your system.
-
Run the script using the following command:
python3 shell_emulator.py
-
You will see a prompt that looks like this:
$
-
Enter your commands after the prompt.
-
exit:
$ exit 0
-
echo:
$ echo Hello, World! Hello, World!
-
type:
$ type cd cd is a shell builtin
-
pwd:
$ pwd /current/working/directory
-
cd:
$ cd /path/to/directory
$ cd ~
The main function initializes the known shell commands and sets up the environment path. It defines a helper function iknow
which is responsible for handling the user input and executing the corresponding commands.
- exit: Exits the shell if the provided argument is
0
. - echo: Prints the arguments to the standard output.
- type: Checks if the command is a shell builtin or an external command and prints the appropriate message.
- pwd: Prints the current working directory.
- cd: Changes the directory to the specified path. Supports
~
for navigating to the home directory.
If a command is not recognized as a known shell command, it checks if it is an executable in the system's PATH and executes it. If the command is not found, it prints an error message.
The cd
command supports changing to the home directory by recognizing the ~
symbol and translating it to the home directory path using os.path.expanduser("~")
.
Feel free to fork this repository, create issues, or submit pull requests if you have any improvements or bug fixes.
This project is licensed under the MIT License.