ShX is a minimalistic, POSIX-compliant command-line shell written in Go. It interprets and executes both built-in commands and external programs, providing a functional and efficient shell experience.
This project is a great learning resource for command parsing, REPL (Read-Eval-Print Loop), process management, and shell scripting.
✅ Built-in Commands
- Supports essential commands like
cd,pwd,echo,exit, andtype.
✅ External Command Execution
- Runs system executables found in
$PATH.
✅ Command Parsing
- Handles single & double quotes, escaping (
\), and arguments.
✅ Redirection Operators
>/1>: Overwritestdout.>>/1>>: Append tostdout.2>: Overwritestderr.2>>: Append tostderr.
✅ Autocompletion
- Single Tab: Auto-completes when there’s a unique match or common prefix.
- Double Tab: Lists all possible matches if multiple exist.
✅ Customized Prompt
- Displays a green
ShXprompt with an arrow (➜) before input:fmt.Fprint(os.Stdout, "\r\033[1;32mShX\033[0m ➜ ")
Ensure Go is installed. Install Go.
git clone https://github.com/ShreyamKundu/ShX.git
cd ShX/cmd/
go build -o ShX main.goStart ShX by running:
./ShXYou'll see a prompt:
ShX ➜ Now you can enter commands.
ShX ➜ echo Hello, ShX!
Hello, ShX!ShX ➜ echo 'Hello, ShX!'
Hello, ShX!ShX ➜ echo Hello\,\ ShX\!
Hello, ShX!ShX ➜ pwd
/home/user/shxRedirect Output to File:
ShX ➜ pwd > cwd.txtShX ➜ cd /usr/localShX ➜ cd ./binShX ➜ cd ..ShX ➜ cd ~ShX ➜ type cd
cd is a shell builtinShX ➜ type ls
ls is /usr/bin/lsShX ➜ type unknowncmd
unknowncmd: not foundShX ➜ exit✅ Ends the session.
Overwrite Output:
ShX ➜ echo "Hello, ShX!" > output.txtAppend Output:
ShX ➜ echo "Appending this line" >> output.txtOverwrite Errors:
ShX ➜ ls /invalidpath 2> error.logAppend Errors:
ShX ➜ ls /invalidpath 2>> error.logIf there’s only one match:
ShX ➜ pw<Tab>
ShX ➜ pwdIf multiple matches exist:
ShX ➜ e<Tab><Tab>
echo exitShX ➜ bas<Tab>
ShX ➜ bashShX executes external commands like ls, grep, and mkdir if found in $PATH:
ShX ➜ ls
main.go shx README.mdHandling Unknown Commands:
ShX ➜ unknowncmd
unknowncmd: command not found- Example:
ls | grep main - Allows chaining commands.
- Implementing
historyto recall past commands. - Storing history in
~/.shx_history.
- Support for background (
bg) and foreground (fg) jobs. - Implementing
jobsto list running jobs. - Handling CTRL+Z to stop processes.
ShX is a lightweight yet powerful shell, ideal for learning and customization. Contributions and feature suggestions are always welcome!
Enjoy using ShX and happy coding! 🚀