在启动时在Ubuntu中设置环境变量(通过脚本) [英] Setting environment variable in Ubuntu at boot time (via script)

查看:485
本文介绍了在启动时在Ubuntu中设置环境变量(通过脚本)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Ubuntu计算机(10.04)上设置几个环境变量,但是我想通过脚本创建它们的值,就像:

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)

我尝试在/etc/environment中进行设置,但这仅逐字复制了rhs

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

我尝试在启动时在/etc/init.d/中执行脚本,但这似乎不起作用.

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

想法?

推荐答案

您需要将导出语句写入/etc/bash.bashrc文件,该文件是系统范围的.bashrc文件,它将为所有系统用户设置环境:)

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.

这篇关于在启动时在Ubuntu中设置环境变量(通过脚本)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆