A powerful command-line shell written in Go with sh-style scripting support, designed for cross-platform compatibility. Works seamlessly on Windows, macOS, and Linux. Gosh, it's good to have a reliable shell everywhere!
Gosh provides a comprehensive set of built-in commands for shell operations. See the Command Reference for detailed documentation of all available commands.
Gosh includes built-in implementations of essential file operations that work consistently across all platforms:
- File Listing:
ls(Unix-style) anddir(Windows-style) with support for long format, hidden files, and human-readable sizes - File Display:
cat(Unix) andtype(Windows) for viewing file contents - File Operations:
cp/copy,mv/move,rm/delfor copying, moving, and removing files and directories - Directory Operations:
mkdir/md,rmdir/rdfor creating and removing directories - Screen Management:
clear(Unix) andcls(Windows) for clearing the terminal
Both Unix-style and Windows-style command names are supported, making the shell familiar to users from any platform!
- Interactive Mode: Run
./goshfor an interactive shell session - Command Mode: Run
./gosh -c "command"to execute a single command and exit - Script Mode: Run
./gosh script.shto execute shell scripts - Control Structures: If statements and case statements supported in both interactive and script modes
- Functions: Define and use shell functions with positional parameters
- Command Chaining: Execute multiple commands sequentially with
; - Unix Pipes: Connect commands with
|to chain operations - Input/Output Redirection: Support for
<,>, and>>operators - Background Execution: Run commands in background with
& - Line Continuation: Split long commands across multiple lines using
\ - Environment Variables: Set and use custom environment variables
- Command Aliases: Create shortcuts for frequently used commands
- Command History: Track previously executed commands
- Quote Handling: Support for single and double quotes in arguments
- Comment Support: Lines starting with
#are treated as comments in scripts - Variable Expansion: Expand environment variables with
$VARand${VAR}syntax - Command Substitution: Execute commands and use their output with
$(command)and`command` - Tilde Expansion: Expand
~to home directory and user paths - Glob Patterns: Use wildcards for filename matching
- Signal Handling: Ctrl-C interrupts running commands without exiting the shell
For detailed information on scripting and advanced features, see the Scripting Guide and Advanced Topics.
- Cross-Platform Features - Learn about dual command support and platform compatibility
- Tab Completion Test Guide - Test and verify tab completion features
- Command Reference - List of all built-in commands and their usage
- Scripting Guide - Learn how to write shell scripts using gosh
- Advanced Topics - Explore more advanced features and techniques
Build gosh for your platform:
# Build for current platform
go build -o gosh
# Cross-compile for different platforms
go build -o gosh.exe # Windows
GOOS=linux go build -o gosh-linux # Linux
GOOS=darwin go build -o gosh-macos # macOSThe resulting binary will include all cross-platform built-in commands and work consistently across different operating systems.
./goshGosh, that was easy!
./gosh -c "command"Execute a single command and exit. Perfect for automation and scripting!
Examples:
./gosh -c "echo 'Hello World'"
./gosh -c "ls -la | grep .go"
./gosh -c "pwd; echo 'Current directory listed above'"
./gosh -c "ls; echo 'Files listed'; pwd"./gosh script.shBy gosh, scripting has never been simpler!
Windows Note: Gosh automatically detects and executes shell scripts on Windows, even though they're not native Windows executables. Scripts with .sh extensions or shell shebang lines work seamlessly across all platforms.
#!/usr/bin/env gosh
# Example gosh script - showcasing cross-platform features!
echo "Hello from gosh!"
pwd
# Cross-platform file operations
echo "=== File Listing (Unix-style) ==="
ls -la
echo "=== File Listing (Windows-style) ==="
dir -l
# Create test directory and files
mkdir -p test_project/src
echo "console.log('Hello World');" > test_project/src/app.js
echo "# Test Project" > test_project/README.md
# Show file contents using both styles
echo "=== File Contents (Unix-style) ==="
cat test_project/README.md
echo "=== File Contents (Windows-style) ==="
type test_project/src/app.js
# Copy and move operations
cp test_project/README.md test_project/README_backup.md
copy test_project/src/app.js test_project/app_copy.js
# Environment variables
export MY_VAR=test
echo "MY_VAR is: $MY_VAR"
# Local variables (shell-only)
local TEMP_VAR="temporary value"
echo "TEMP_VAR is: $TEMP_VAR"
# Pipe examples - gosh, pipes are powerful!
echo "testing pipe functionality" | wc -w
ls -la | head -5
# Clean up
rm -rf test_project
# Clear screen (choose your style!)
# clear # Unix-style
# cls # Windows-style
echo "Gosh darn it, that's some fine cross-platform scripting!"# Basic usage
ls -la
echo "Hello, World!"
# Cross-platform file operations - use either style!
ls -l # Unix-style file listing
dir -l # Windows-style file listing
cat README.md # Unix-style file display
type README.md # Windows-style file display
cp file.txt backup.txt # Unix-style copy
copy file.txt backup.txt # Windows-style copy
# Pipes and redirection
ls | grep ".go" > go_files.txt
echo "Hello" >> output.txt
# Variables and expansion
export MY_VAR="Hello" # Environment variable
local TEMP_VAR="temporary" # Local variable (shell-only)
echo "$MY_VAR, $(whoami)!"
echo "Temp: $TEMP_VAR"
# Command chaining
echo "Starting..."; pwd; echo "Done!"
# Cross-platform directory operations
mkdir -p projects/gosh # Create nested directories
cp -r src/ backup/ # Copy directory recursively
rm -rf temp/ # Remove directory and contents
clear # Clear screen (Unix-style)
cls # Clear screen (Windows-style)
# Line continuation for long commands
echo "This is a very long command" \
"that spans multiple lines" \
"for better readability"For comprehensive examples and tutorials, see the Scripting Guide.
Gosh implements proper signal handling to provide a better user experience:
- Ctrl-C (SIGINT): Interrupts the currently running command but does not exit the shell
- Ctrl-C while idle: Shows a new prompt but does not exit the shell
- The shell remains active and returns to the prompt in all cases
- This allows you to stop long-running commands without losing your shell session
- The shell can only be exited using the
exitcommand or EOF (Ctrl-D)
To test the signal handling functionality:
- Start the shell:
./gosh - Press Ctrl-C while idle - the shell should show a new prompt but not exit
- Run a long command:
sleep 10 - Press Ctrl-C to interrupt the sleep command
- The shell should return to the prompt without exiting
- Press Ctrl-C again while idle - should show new prompt, not exit
- Use
exitto properly exit the shell
Gosh, that's convenient!
Gosh is organized into multiple modules for maximum readability and maintainability. For detailed architecture information, see the Advanced Topics documentation.
Cross-Platform Support: Gosh is designed and tested to work seamlessly across multiple operating systems:
- Windows: Full support with both Unix-style (
ls,cat,cp) and Windows-style (dir,type,copy) commands, plus automatic shell script execution - macOS: Native support with all Unix-style commands
- Linux: Complete compatibility with standard Unix commands
Shell Script Execution: Gosh automatically handles shell scripts on all platforms:
- Scripts with
.shextension work on Windows without modification - Unix/Linux/macOS: Shebang lines are respected and scripts run with the specified interpreter (bash, zsh, etc.)
- Windows: Shebang lines are recognized but all scripts run through gosh (Windows doesn't support shebangs natively)
- Scripts without shebangs show a warning on Unix-like systems and run with gosh
- No "not a valid Win32 application" errors on Windows
The shell automatically handles platform-specific differences like file paths, permissions, and command conventions. Gosh, it's truly portable!
There are probably many bugs in gosh. Please report any bugs or issues to the GitHub issue tracker.
This project is open source and available under the MIT License.
