Table of Contents
Shell Script Execution
Gosh provides seamless shell script execution across all platforms - gosh, cross-platform scripting has never been easier!
Unix-like Platform Shebang Support
On Unix-like platforms (Linux, macOS), gosh now respects shebang lines and executes scripts with their specified interpreters:
- Shebang Detection: Scripts with shebangs like
#!/bin/bash
,#!/usr/bin/env zsh
are detected automatically - Interpreter Execution: Scripts run with their specified interpreters (bash, zsh, python, etc.)
- Error Handling: If the specified interpreter isn't found, gosh shows an error message
- Missing Shebang Warning: Scripts without shebangs get a gosh pun warning and run with gosh
- Supported Formats: Both direct paths (
#!/bin/bash
) and env-style (#!/usr/bin/env bash
)
# On Unix-like platforms:
./bash_script.sh # Runs with bash if shebang is #!/bin/bash
./zsh_script.sh # Runs with zsh if shebang is #!/usr/bin/env zsh
./no_shebang.sh # Shows warning: "By gosh, I'll run it with gosh and hope for the best!"
Windows Shell Script Support
On Windows, gosh automatically detects and executes shell scripts that would normally fail with "not a valid Win32 application" errors:
- Automatic Detection: Scripts with
.sh
extension or shell shebang lines are automatically recognized - Transparent Execution: All shell scripts are executed through gosh itself, providing full compatibility
- Shebang Recognition: Scripts with
#!/bin/sh
,#!/bin/bash
,#!/usr/bin/env gosh
, etc. are recognized but run through gosh - Argument Passing: All script arguments are properly passed through
# These all work on Windows now:
./script.sh arg1 arg2
gosh script.sh arg1 arg2
gosh -c "script.sh arg1 arg2"
# Even scripts without .sh extension work if they have a shebang:
./my_script # Works if it starts with #!/usr/bin/env gosh
Cross-Platform Script Examples
#!/usr/bin/env gosh
# This script works identically on Windows, macOS, and Linux
# Gosh, it's truly portable!
# Detect platform in a way that works with gosh
if command -v uname >/dev/null 2>&1; then
local PLATFORM=$(uname -s)
else
local PLATFORM="Windows"
fi
echo "Running on: $PLATFORM"
echo "Script arguments: $@"
# Use cross-platform commands
ls -la # Works on all platforms
echo "Files listed above"
# Environment variables work the same way
export MY_VAR="cross-platform value"
echo "MY_VAR: $MY_VAR"
echo "Gosh darn it, that's some fine cross-platform scripting!"
Before and After
Before gosh's Windows shell script support:
C:\> script.sh
'script.sh' is not recognized as an internal or external command,
operable program or batch file.
C:\> .\script.sh
Access is denied.
With gosh - gosh, it just works!
gosh> ./script.sh
Hello from gosh script!
Cross-platform execution successful!
Gosh, that was easy!
Dual Command Support
Gosh supports both Unix-style and Windows-style commands, allowing you to use whichever style you prefer:
File Operations
Operation | Unix Style | Windows Style | Description |
---|---|---|---|
List files | ls -la |
dir -l |
Both work on all platforms |
Display file | cat file.txt |
type file.txt |
Show file contents |
Copy files | cp src dest |
copy src dest |
Copy files or directories |
Move files | mv old new |
move old new |
Move or rename files |
Clear screen | clear |
cls |
Clear the terminal screen |
Example Usage
# Use either style - both work everywhere!
ls -la # 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
# Mix and match as you prefer
ls *.txt | head -5 # Unix-style listing with Unix head
dir *.txt | head -5 # Windows-style listing with Unix head
File Path Handling
Gosh automatically handles different path conventions across platforms:
Path Separators
- Unix/macOS: Forward slashes (
/
) - Windows: Both forward slashes (
/
) and backslashes (\
)
# These all work on Windows:
cd /path/to/directory # Forward slashes
cd \path\to\directory # Backslashes
cd path/to/directory # Relative with forward slashes
cd path\to\directory # Relative with backslashes
# Tilde expansion works with both separators on Windows:
cd ~/Documents # Unix-style
cd ~\Documents # Windows-style
Cross-Platform Path Examples
# Scripts that work everywhere
export PROJECT_DIR="$HOME/projects/myapp" # Unix-style (works everywhere)
export CONFIG_DIR="$HOME/.config/myapp" # Unix-style config
# Windows-specific paths (when needed)
export WINDOWS_CONFIG="$HOME\AppData\Local\myapp" # Windows-style
# Gosh handles the differences automatically!
Tab Completion Behavior
Gosh adapts its tab completion behavior to match platform conventions - gosh, it's like having a native shell everywhere!
Platform-Specific Case Sensitivity
Platform | Tab Completion | Built-in Commands | External Commands | Example |
---|---|---|---|---|
Windows | Case-insensitive | Case-insensitive | Case-insensitive | EC[TAB] → echo |
Linux/Unix/macOS | Case-sensitive | Case-insensitive | Case-sensitive | ec[TAB] → echo |
Why Platform-Specific?
This design respects user expectations on each platform:
- Windows Users: Accustomed to case-insensitive file systems (NTFS) and shells (cmd.exe, PowerShell)
- Unix Users: Expect case-sensitive behavior like bash, zsh, and traditional Unix tools
- Built-in Commands: Always case-insensitive for convenience (echo, cd, pwd, etc.)
- External Commands: Follow platform conventions (case-insensitive on Windows, case-sensitive on Unix)
Examples in Action
# Windows behavior - gosh, it's forgiving everywhere!
gosh> EC[TAB] # Completes to "echo"
gosh> ECho "Hello" # Built-in: executes successfully
Hello
gosh> DIR # External: executes successfully (Windows is case-insensitive)
# Linux/Unix/macOS behavior - gosh, it's precise where it matters!
gosh> EC[TAB] # No completion (case-sensitive)
gosh> ec[TAB] # Completes to "echo"
gosh> ECho "Hello" # Built-in: still executes successfully!
Hello
gosh> LS # External: may fail (case-sensitive)
bash: LS: command not found
gosh> ls # External: works correctly
# File completion respects platform conventions too
# Windows: README[TAB] → README.md (case-insensitive)
# Unix: readme[TAB] → readme.txt (case-sensitive)
💡 Best of Both Worlds
Tab completion follows platform conventions for familiarity, while command execution remains case-insensitive everywhere for maximum usability. Gosh darn it, that's smart design!
Environment Variables
Environment variables work consistently across all platforms in gosh:
# Set environment variables (works everywhere)
export MY_VAR="Hello World"
export PATH="$PATH:/new/path"
# Use environment variables
echo $MY_VAR
echo "Current PATH: $PATH"
# Platform detection in scripts
if command -v uname >/dev/null 2>&1; then
local PLATFORM=$(uname -s)
else
local PLATFORM="Windows"
fi
export PLATFORM
echo "Running on: $PLATFORM"
Cross-Platform Examples
Complete Cross-Platform Script
#!/usr/bin/env gosh
# Cross-platform build script - gosh, it works everywhere!
echo "=== Cross-Platform Build Script ==="
# Detect platform in a way that works with gosh
if command -v uname >/dev/null 2>&1; then
local PLATFORM=$(uname -s)
else
local PLATFORM="Windows"
fi
echo "Platform: $PLATFORM"
# Create project structure (works on all platforms)
mkdir -p build/src
mkdir -p build/dist
# Copy source files using both command styles
echo "Copying source files..."
cp -r src/* build/src/ # Unix-style
copy README.md build/ # Windows-style
# List files using preferred style
echo "=== Build Directory (Unix-style) ==="
ls -la build/
echo "=== Build Directory (Windows-style) ==="
dir -l build/
# Environment setup
local BUILD_DATE=$(date +%Y-%m-%d 2>/dev/null)
if [ -z "$BUILD_DATE" ]; then
local BUILD_DATE="today"
fi
export BUILD_DATE
export BUILD_VERSION="1.0.0"
echo "Build completed on $BUILD_DATE"
echo "Version: $BUILD_VERSION"
echo "Gosh, that was a successful cross-platform build!"
File Processing Script
#!/usr/bin/env gosh
# Process files across platforms - by gosh, it's universal!
# Works with both path separators - gosh, that's flexible!
for file in logs/*.txt logs\*.log; do
if [ -f "$file" ]; then
echo "Processing: $file"
# Use both command styles - gosh, variety is the spice of life!
echo "=== File info (Unix-style) ==="
cat "$file" | head -5
echo "=== File info (Windows-style) ==="
type "$file" | head -5
# Create backup with timestamp
local BACKUP_DATE=$(date +%Y%m%d 2>/dev/null)
if [ -z "$BACKUP_DATE" ]; then
local BACKUP_DATE="backup"
fi
local backup_name="backup_$(basename "$file")_$BACKUP_DATE"
cp "$file" "backups/$backup_name"
fi
done
echo "File processing complete - gosh, that was efficient!"
Tab Completion Demo Script
#!/usr/bin/env gosh
# Demonstrate platform-aware tab completion - gosh, it's educational!
echo "=== Tab Completion Demo ==="
# Detect platform for demonstration
if command -v uname >/dev/null 2>&1; then
local PLATFORM=$(uname -s)
else
local PLATFORM="Windows"
fi
echo "Platform: $PLATFORM"
if [ "$PLATFORM" = "Windows" ]; then
echo "On Windows, try typing 'EC' and press TAB - it should complete to 'echo'"
echo "Gosh, case-insensitive completion makes Windows users feel at home!"
echo ""
echo "Command execution examples:"
echo " ECho Hello # Built-in: works"
echo " DIR # External: works (Windows is case-insensitive)"
else
echo "On Unix/Linux/macOS, try typing 'ec' and press TAB - it should complete to 'echo'"
echo "But 'EC' won't complete - gosh, that's Unix precision for you!"
echo ""
echo "Command execution examples:"
echo " ECho Hello # Built-in: works (gosh built-ins are always case-insensitive)"
echo " LS # External: may fail (Unix is case-sensitive for external commands)"
echo " ls # External: works correctly"
fi
echo ""
echo "Built-in commands work case-insensitively on ALL platforms!"
echo "External commands follow platform conventions - gosh darn it, that's smart!"
💡 Pro Tip - Gosh, That's Helpful!
Write your scripts using Unix-style commands and paths for maximum portability. Gosh will handle the platform differences automatically. When you need Windows-specific behavior, you can mix in Windows-style commands as needed. Remember:
- Built-in commands (echo, cd, pwd, etc.) work case-insensitively everywhere
- External commands follow platform conventions (case-insensitive on Windows, case-sensitive on Unix)
- Tab completion adapts to your platform for natural behavior
Gosh, it's the best of both worlds!