← 返回
未分类 中文

Env Loader

Shell-agnostic .env file loader. Generates a POSIX-compatible script to safely load environment variables from .env files across bash, zsh, dash, and ash. Us...
跨Shell的 .env 文件加载器。生成符合 POSIX 标准的脚本,可在 bash、zsh、dash、ash 中安全加载 .env 文件中的环境变量。用法...
wuhaichao87
未分类 clawhub v1.0.0 1 版本 99635 Key: 无需
★ 0
Stars
📥 273
下载
💾 0
安装
1
版本
#latest

概述

Env Loader

Generates and validates POSIX-compatible .env loading scripts that work consistently across bash, zsh, dash, and ash.

Problem It Solves

source .env behaves differently across shells:

  • zsh: Strips quotes from values correctly
  • bash/dash: Preserves quotes as part of the value ("value" → includes the quotes)
  • All shells: source only assigns, does not export — child processes can't see the variables

This causes silent failures in deployment when .env files contain quoted values or special characters.

Usage

Generate the Loader Script

Run the bundled script or use the template:

bash ~/.openclaw/skills/env-loader/scripts/generate-loader.sh /path/to/project

This creates load-env.sh in the target directory.

Use in Deployment Scripts

# Instead of: source .env
# Use:
. ./load-env.sh .env

Validate an Existing .env File

bash ~/.openclaw/skills/env-loader/scripts/validate-env.sh /path/to/.env

Checks for common issues: unquoted special characters, inline comments, non-POSIX variable names.

Key Design Principles

  1. POSIX-only syntax — no bashisms, no zsh-isms, works in dash/ash
  2. Manual key=value parsing — never source or eval the .env file directly
  3. Explicit quote stripping — removes surrounding single or double quotes consistently
  4. Key validation — only allows [A-Za-z_][A-Za-z0-9_]* as variable names
  5. Explicit export — every parsed variable is exported for child processes

References

See references/env-pitfalls.md for a detailed catalog of shell-specific .env parsing pitfalls.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-20 05:42 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

developer-tools

ClawHub发布工具

wuhaichao87
将本地技能发布到ClawHub平台,支持设置slug、名称、版本、路径及更新日志参数。
★ 0 📥 702
productivity

购物助手

wuhaichao87
智能购物助手,提供淘宝、京东、拼多多优惠券查询、全网比价、价格保护、历史价格及降价提醒服务。
★ 4 📥 1,086
productivity

淘宝客全能工具箱

wuhaichao87
提供淘宝、京东、拼多多商品链接转链、跨平台比价、一键价保及佣金追踪的实用工具箱。
★ 1 📥 1,308