Setting environment variable in Ubuntu at boot time (via script)

余生长醉 提交于 2019-12-07 06:04:13

问题


I'd like to set a couple of environment variables on an Ubuntu machine (10.04), but I want to create their value via a script, much like:

export THE_ENV_VAR=$(script_to_execute_and_use_stdout_from)

I've tried setting in /etc/environment, but that only copies rhs verbatim

I've tried executing a script in /etc/init.d/ at startup, but that does not seem to work.

Ideas?


回答1:


You need to write your export statement into /etc/bash.bashrc file, which is a system wide .bashrc file that will set environments for all system users :)

Edit: One way to do this is to populate a cache file during boot, and let the user scripts read from that cached file.



来源:https://stackoverflow.com/questions/7745926/setting-environment-variable-in-ubuntu-at-boot-time-via-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!