A lightweight shell implementation in Java that supports basic Unix-like commands. This shell provides a minimal command-line interface with support for common shell operations.
-
Basic command prompt interface (
$) -
Built-in commands:
pwd- Print working directorycd- Change directory (supports absolute paths and~for home directory)echo- Print text to console (supports both quoted and unquoted strings)type- Display information about command typeexit- Exit the shell
-
External command execution through PATH lookup
-
Path normalization and validation
-
Home directory resolution (
~)
- Java 11 or higher
java.nio.filesupport- Operating system with PATH environment variable
- Clone this repository:
git clone https://github.com/yourusername/java-shell.git- Compile the Java file:
javac Main.java- Run the shell:
java MainThe shell provides a command prompt ($) where you can enter commands:
$ pwd
/current/working/directory
$ echo "Hello World"
Hello World
$ cd ~
$ type echo
echo is a shell builtin-
pwd- Displays the current working directory
-
cd [directory]- Changes the current working directory
- Supports absolute paths and
~for home directory - Example:
cd ~/Documentsorcd /usr/local
-
echo [text]- Prints text to the console
- Supports both quoted and unquoted strings
- Example:
echo Hello Worldorecho "Hello World"
-
type [command]- Displays whether a command is a shell builtin or its location in PATH
- Example:
type pwdortype java
-
exit 0- Exits the shell
- Uses Java NIO for file operations
- Implements PATH lookup for external commands
- Handles both built-in commands and external executables
- Supports basic string parsing for command arguments
- Implements working directory management
- Basic command parsing (no advanced shell features)
- Limited support for command arguments and flags
- No pipeline support
- No environment variable expansion
- No wildcard support
- No command history
Feel free to submit issues and enhancement requests!