Files
rush/docs/src/getting-started/quick-start.md
tototomate123 af0a1632c0 major changes
- Added documentation via mdbook
- Created basic VS code extension
- Implemented if else blocks and changed some syntax
- fixed some issues
2025-11-02 19:56:26 +01:00

2.8 KiB

Quick Start

⚠️ This documentation is AI-generated and may contain errors.

This guide will walk you through creating your first Rush script.

Your First Script

Create a file called hello.rsh:

#!/usr/bin/env rush

# Variables are assigned with =
NAME = "Rush"
echo "Hello from $NAME!"

Run it:

rush hello.rsh

Output:

Hello from Rush!

Variables and Interpolation

Variables are automatically interpolated in strings:

PROJECT = "my-app"
VERSION = "1.0.0"
FULL_NAME = "$PROJECT-v$VERSION"

echo "Building $FULL_NAME"
# Output: Building my-app-v1.0.0

Using Built-in Variables

Rush provides several built-in variables:

echo "Current user: $USER"
echo "Home directory: $HOME"

if $IS_ROOT {
    echo "Running as root"
} else {
    echo "Running as normal user"
}

Conditional Logic

Use if/else for branching:

ENV = "production"

if $ENV {
    echo "Environment: $ENV"
}

if not $IS_ROOT {
    echo "Warning: Not running as root"
} else {
    echo "Running with elevated privileges"
}

Loops

Iterate over items with for:

# Loop over space-separated items
for name in Alice Bob Charlie {
    echo "Hello, $name!"
}

# Use variables in loops
SERVERS = "web-1 web-2 web-3"
for server in web-1 web-2 web-3 {
    echo "Deploying to $server"
}

Parallel Execution

Run tasks concurrently:

parallel {
    run {
        echo "Task 1: Starting..."
        echo "Task 1: Complete"
    }
    
    run {
        echo "Task 2: Starting..."
        echo "Task 2: Complete"
    }
    
    run {
        echo "Task 3: Starting..."
        echo "Task 3: Complete"
    }
}

echo "All tasks finished"

The output from parallel blocks may be interleaved since they run concurrently.

A Complete Example

Here's a more complete script showing multiple features:

#!/usr/bin/env rush

# Configuration
PROJECT = "web-app"
ENV = "staging"
DEPLOY_DIR = "/var/www/$PROJECT"

echo "Deployment Script for $PROJECT"
echo "Environment: $ENV"
echo ""

# Pre-flight checks
if not $IS_ROOT {
    echo "Warning: Not root. Some operations may fail."
}

# Build steps
echo "Running build steps:"
for step in lint test build {
    echo "  - $step"
}

# Deploy to multiple servers in parallel
echo ""
echo "Deploying to $ENV servers..."

parallel {
    run {
        echo "[server-1] Deploying $PROJECT"
        echo "[server-1] Complete"
    }
    
    run {
        echo "[server-2] Deploying $PROJECT"
        echo "[server-2] Complete"
    }
}

echo ""
echo "Deployment complete!"

Next Steps

Learn more about Rush's features: