简体   繁体   English

为什么在 bash 脚本中导出 env var 不会影响 env?

[英]Why exporting env var in bash script does not affect env?

I want to set env variable in shell script.我想在 shell 脚本中设置 env 变量。 Shell script content is: Shell脚本内容为:

#!/bin/bash
export XDEBUG_CONFIG="idekey=PHPSTORM"

I tried both bash bin/enable_debug and bin/enable_debug .我尝试了bash bin/enable_debugbin/enable_debug After both command I get:在这两个命令之后,我得到:

$ echo $XDEBUG_CONFIG

$

However if I run export XDEBUG_CONFIG="idekey=PHPSTORM" directly in cli it works.但是,如果我直接在 cli 中运行export XDEBUG_CONFIG="idekey=PHPSTORM"它可以工作。 What's wrong with my method?我的方法有什么问题?

You can try running your script as below:您可以尝试运行您的脚本,如下所示:

. bin/enable_debug

OR或者

source bin/enable_debug

as indicated by @Aserre如@Aserre 所示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM