将环境变量从Makefile导出到用户环境

编程入门 行业动态 更新时间:2024-10-25 14:23:05
本文介绍了将环境变量从Makefile导出到用户环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找如何从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导出到用户环境

本文发布于:2023-11-24 09:15:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624625.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:环境变量   环境   导出到   用户   Makefile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!