Variables
Defining Variables
Section titled “Defining Variables”name = "Jake"version = "1.0.0"build_dir = "dist"Using Variables
Section titled “Using Variables”Use {{variable}} syntax in commands:
greeting = "Hello"target = "World"
task greet: echo "{{greeting}}, {{target}}!"Output: Hello, World!
Variable Scope
Section titled “Variable Scope”Variables are global and available to all recipes:
project = "myapp"
task build: echo "Building {{project}}"
task test: echo "Testing {{project}}"Environment Variables
Section titled “Environment Variables”Loading .env Files
Section titled “Loading .env Files”@dotenv # Load .env@dotenv ".env.local" # Load specific fileFiles are loaded in order; later files override earlier ones.
Exporting Variables
Section titled “Exporting Variables”@export NODE_ENV=production@export DEBUG=falseExported variables are passed to all subprocess commands.
Using in Commands
Section titled “Using in Commands”Use $VAR or ${VAR} syntax:
task show: echo "Node: $NODE_ENV" echo "Debug: ${DEBUG}".env File Format
Section titled “.env File Format”# Database settingsDATABASE_URL=postgres://localhost/myappDB_POOL_SIZE=10
# API Keys (use quotes for special chars)API_KEY="abc123!@#"
# Empty valuesEMPTY_VAR=
# Escape sequencesMULTILINE=line1\nline2WINDOWS_PATH=C:\\Users\\NameSupported escapes: \n, \t, \r, \\, \", \', \$
Requiring Variables
Section titled “Requiring Variables”Validate required environment variables:
@require API_KEY DATABASE_URL
task deploy: echo "Deploying with $API_KEY"Jake exits with an error if any required variable is missing.