Setting environment variable in shell script does not make it visible to the shell

后端 未结 2 1552
失恋的感觉
失恋的感觉 2020-12-08 14:27

I want to use a shell script that I can call to set some environment variables. However, after the execution of the script, I don\'t see the environment variable using \"pri

2条回答
  •  醉酒成梦
    2020-12-08 14:47

    Another alternative would be to have the script print the variables you want to set, with echo export VAR=value and do eval "$(./test.sh)" in your main shell. This is the approach used by various programs [e.g. resize, dircolors] that provide environment variables to set.

    This only works if the script has no other output (or if any other output appears on stderr, with >&2)

提交回复
热议问题