You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用PowerShell将环境变量定义语句写入文件?

解决方案
  • 使用单引号包裹写入内容:PowerShell中,单引号字符串不会解析变量,会完整保留原始内容

    Add-Content -Path test.bat -Value '$env:CI_JOB_STAGE = preprocessing'
    
  • 或者转义$符号:用PowerShell的转义符(反引号)对$`进行转义,避免被识别为变量引用

    Add-Content -Path test.bat -Value "`$env:CI_JOB_STAGE = preprocessing"
    
  • 补充说明:如果你的实际需求是在bat文件中设置环境变量(而非写入PowerShell格式语句),bat的标准语法为set CI_JOB_STAGE=preprocessing,对应的写入命令为:

    Add-Content -Path test.bat -Value 'set CI_JOB_STAGE=preprocessing'
    

内容的提问来源于stack exchange,提问作者IzaeDA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.20 15:42:01