我正在寻找如何从Makefile环境变量中导出要在用户环境中公开的变量,因此应该可以从用户外壳程序中访问从Makefile中导出这些变量.
I'm looking how to export from a Makefile environment variables to be exposed in the userland environment so exporting these variables from the Makefile should be accessible from the user shell.
我尝试了 make的export 但据我了解并尝试过,它不会导出到Makefile外部.
I have tried make's export but as I understand and have tried does not export to outside of Makefile.
这样的想法是用优雅的方式填充 Docker Compose环境变量并在用户外壳中准备好使用这些变量.
The idea of this is to populate Docker Compose environment variables in a elegant way and have these variables ready to use in the user shell also.
这是我尝试使用make的export的一部分:
This is a fragment of what I've tried with make's export:
include docker.env export $(shell sed -n '/=/p' docker.env) SHELL := /bin/bash run: @docker-compose -f my-service.yml up -d推荐答案
根据 ArchWiki ,Bash的每个过程...
According with ArchWiki, each process of Bash...
每个进程将其环境存储在/proc/$ PID/environ文件中.
Each process stores their environment in the /proc/$PID/environ file.
因此,一旦使执行source,export或任何其他命令来设置新的环境变量,它将仅应用于该进程.
so once Make execute a source, export or any other command to set a new environment variable it will be applied only for that process.
作为解决方法,我已经在bash启动文件中编写了代码,这样一来,一旦加载了新的bash shell,这些变量便会进入全局环境:
As workaround I've written in the bash startup file so the variables will be in the global environment as soon as a new bash shell is loaded:
SHELL := /bin/bash RC := ~/.bashrc ENV := $(shell sed -n '/=/p' docker.env) test: @$(foreach e,$(ENV),echo $(e) >> $(RC);) \更多推荐
将环境变量从Makefile导出到用户环境
发布评论