export
Output environment variables in various formats for integration with external tools.
Synopsis
Section titled “Synopsis”kiln export [options]The export command decrypts and outputs all environment variables from a file in formats suitable for shell sourcing, JSON processing, or YAML configuration.
Options
Section titled “Options”--file,-f: Environment file to export (default:default)--format: Output format:shell,json, oryaml(default:shell)
Examples
Section titled “Examples”Shell Format (Default)
Section titled “Shell Format (Default)”kiln export# export DATABASE_URL='postgresql://localhost:5432/myapp'# export API_KEY='sk-1234567890abcdef'# export DEBUG_MODE='true'JSON Format
Section titled “JSON Format”kiln export --format json# {# "DATABASE_URL": "postgresql://localhost:5432/myapp",# "API_KEY": "sk-1234567890abcdef",# "DEBUG_MODE": "true"# }YAML Format
Section titled “YAML Format”kiln export --format yaml# API_KEY: sk-1234567890abcdef# DEBUG_MODE: "true"Specific Environment File
Section titled “Specific Environment File”kiln export --file production --format jsonkiln export --file staging --format shellOutput Formats
Section titled “Output Formats”Shell Format
Section titled “Shell Format”Generates export statements suitable for shell sourcing:
export DATABASE_URL='postgresql://localhost:5432/myapp'export API_KEY='sk-1234567890abcdef'export PORT='8080'Features:
- Values are properly shell-escaped with single quotes
- Special characters are handled automatically
- Variables are sorted alphabetically
- Direct sourcing:
eval "$(kiln export)"
JSON Format
Section titled “JSON Format”Outputs a JSON object with all variables:
{ "DATABASE_URL": "postgresql://localhost:5432/myapp", "API_KEY": "sk-1234567890abcdef", "PORT": "8080"}Features:
- Pretty-printed with 2-space indentation
- Proper JSON escaping for special characters
- Compatible with
jqand other JSON tools - Machine-readable format
YAML Format
Section titled “YAML Format”Outputs variables as YAML key-value pairs:
DATABASE_URL: postgresql://localhost:5432/myappAPI_KEY: sk-1234567890abcdefPORT: "8080"Features:
- Clean, human-readable format
- Automatic type inference
- Compatible with YAML parsers
- Suitable for configuration files
Security Features
Section titled “Security Features”Memory Safety
Section titled “Memory Safety”- Variables are wiped from memory after output
- No sensitive data persists after command completion
- Secure cleanup on interruption
Access Control
Section titled “Access Control”Export respects file-level permissions:
[files.production]filename = "prod.env"access = ["admin", "deploy"]
[files.development]filename = "dev.env"access = ["*"]Integration Patterns
Section titled “Integration Patterns”Shell Environment Loading
Section titled “Shell Environment Loading”# Load variables into current shelleval "$(kiln export --file production)"
# Or save to file for later sourcingkiln export --file production > /tmp/prod.envsource /tmp/prod.envDocker Integration
Section titled “Docker Integration”# Generate Docker environment filekiln export --file production --format shell > docker.envdocker run --env-file docker.env myapp:latest
# Or use JSON for docker-composekiln export --file production --format json > compose.env.jsonCI/CD Pipelines
Section titled “CI/CD Pipelines”# GitHub Actionskiln export --format json | jq -r 'to_entries[] | "\(.key)=\(.value)"' >> $GITHUB_ENV
# GitLab CIkiln export --format shell > variables.envConfiguration Management
Section titled “Configuration Management”# Generate Kubernetes ConfigMapkiln export --format yaml > configmap-data.yaml
# Ansible variableskiln export --format json > ansible-vars.jsonWorkflow Examples
Section titled “Workflow Examples”Development Setup
Section titled “Development Setup”# Export development environmentkiln export --file dev > .env.localecho ".env.local" >> .gitignore
# Load into current sessioneval "$(kiln export --file dev)"npm startProduction Deployment
Section titled “Production Deployment”# Export for deployment scriptkiln export --file production --format json > deploy-config.json
# Validate required variablesrequired_vars=("DATABASE_URL" "API_KEY" "JWT_SECRET")export_json=$(kiln export --file production --format json)for var in "${required_vars[@]}"; do if ! echo "$export_json" | jq -e "has(\"$var\")" > /dev/null; then echo "Missing required variable: $var" exit 1 fidoneConfiguration Backup
Section titled “Configuration Backup”# Backup all environmentsfor env in dev staging production; do kiln export --file "$env" --format json > "backup-$env.json"done
# Create restore scriptfor env in dev staging production; do echo "# Restore $env environment" jq -r 'to_entries[] | "kiln set \(.key) \"\(.value)\" --file '$env'"' "backup-$env.json"done > restore.shCross-Platform Configuration
Section titled “Cross-Platform Configuration”# Windows batch filekiln export --format shell | sed 's/export /set /' > vars.bat
# PowerShellkiln export --format json | jq -r 'to_entries[] | "$env:\(.key)=\"\(.value)\""' > vars.ps1Error Handling
Section titled “Error Handling”Access Denied
Section titled “Access Denied”kiln export --file production# Error: security error: access denied for 'production' (check file permissions in kiln.toml)File Not Found
Section titled “File Not Found”kiln export --file nonexistent# Error: configuration error: file 'nonexistent' not configured (check kiln.toml file definitions)Empty Environment
Section titled “Empty Environment”kiln export --file empty# (No output - empty environment file produces no variables)Performance Considerations
Section titled “Performance Considerations”Large Environment Files
Section titled “Large Environment Files”- Export time scales with number of variables
- Memory usage proportional to total content size
- Output generation time varies by format (JSON > YAML > shell)
Format-Specific Performance (for very large files)
Section titled “Format-Specific Performance (for very large files)”- Shell: Fastest, minimal processing
- JSON: Moderate, requires JSON encoding
- YAML: Slowest, complex formatting rules
Best Practices
Section titled “Best Practices”Security
Section titled “Security”- Redirect output carefully to avoid exposing secrets
- Use temporary files with proper permissions for sensitive exports
- Clean up exported files containing production secrets
- Audit export operations in production environments
Integration
Section titled “Integration”- Validate exports before using in deployment scripts
- Handle empty environments gracefully in automation
- Use appropriate formats for target systems
- Version control export scripts but not exported secrets
Automation
Section titled “Automation”# Robust export with error handlingexport_vars() { local env_file="$1" local format="${2:-shell}"
if ! kiln export --file "$env_file" --format "$format" 2>/dev/null; then echo "Failed to export $env_file environment" >&2 return 1 fi}
# Usage in deployment scriptif vars=$(export_vars production json); then echo "Successfully exported production variables" # Process $varselse echo "Export failed, aborting deployment" exit 1fiComparison with Alternatives
Section titled “Comparison with Alternatives”vs. get command
Section titled “vs. get command”export: All variables, various formatsget: Single variable, immediate use
vs. run command
Section titled “vs. run command”export: Generates output for external userun: Direct command execution with environment
vs. edit command
Section titled “vs. edit command”export: Read-only output generationedit: Interactive modification interface
Advanced Usage
Section titled “Advanced Usage”Custom Formatting
Section titled “Custom Formatting”# Custom shell format with prefixeskiln export --format json | jq -r 'to_entries[] | "export MYAPP_\(.key)=\(.value)"'
# Environment-specific prefixesenv_name="production"kiln export --file "$env_name" --format json | \ jq -r --arg env "$env_name" 'to_entries[] | "export \($env | ascii_upcase)_\(.key)=\(.value)"'Filtered Exports
Section titled “Filtered Exports”# Export only specific variableskiln export --format json | jq 'with_entries(select(.key | startswith("API_")))'
# Export secrets onlykiln export --format json | jq 'with_entries(select(.key | contains("SECRET") or contains("KEY")))'Template Integration
Section titled “Template Integration”# Mustache templateskiln export --format json > config.jsonmustache config.json template.conf > final.conf
# envsubsteval "$(kiln export)"envsubst < template.conf > final.conf