如何使用shell脚本.sh设置全局环境变量 [英] How to set global environment variables using shell script .sh

查看:995
本文介绍了如何使用shell脚本.sh设置全局环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .sh 文件,本地在我的shell中设置一些环境变量 source my_env.sh

I have a .sh file that locally sets some environment variables in my shell source my_env.sh.

#!/bin/sh
echo "Setting up local environment variables"
export MY_URL="http://domain.com"
echo "Done"

这只设置变量为该会议。这意味着我在不同会话下运行的Python Celery和Supervisor应用程序无法访问它们。我明白我可以在一个用户身上运行它们,但是我想知道在Ubuntu上是否使用与上述相同的shell脚本,如果我可以设置这些变量,以便所有应用程序可以全局访问,无论用户还是会话?

This only sets the variables for that session. Which means that my Python Celery and Supervisor apps which run under a different session cannot access them. I understand I can run them under a user, but I want to know if on Ubuntu using the same shell script above if I can set the variables so they are globally accessible to all applications regardless of users or session?

推荐答案

根据 Ubuntu的env变量doc 最好的方式是


一个适用于影响整个系统的环境变量设置的文件(而不仅仅是一个特定的用户)是/ etc / environment

A suitable file for environment variable settings that affect the system as a whole (rather than just a particular user) is /etc/environment

这是假设你不介意为整个机器设置它们。

That's assuming you don't mind having them set for the whole machine.

这篇关于如何使用shell脚本.sh设置全局环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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