How to set global environment variables using shell script .sh

前端 未结 3 762
眼角桃花
眼角桃花 2021-01-17 06:01

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

#!/bin/sh
echo \"Setting up local env         


        
相关标签:
3条回答
  • 2021-01-17 06:22

    export your variables in the "/etc/profile".

    NOTE: This will make it global for each shell sessions for any user. If you wish to set this variable for every session for a specific user, set it in that user's "~/.profile".

    0 讨论(0)
  • 2021-01-17 06:28

    According to Ubuntu env variables doc the best way would be

    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.

    0 讨论(0)
  • 2021-01-17 06:31

    If you are using bashrc or zshrc you can source the shell file which sets the environment variables across the sessions or precisely loads all the environment variables in each session.

    source location/shell-script-sets-env.sh  
    

    The zshrc and bashrc is available in your $HOME directory. or ~/.zshrc and ~/.bashrc. The current shell can be looked via

    echo $SHELL 
    

    Have a look at setting env permanently for adding it to the profile.

    0 讨论(0)
提交回复
热议问题