开发者

How can I automatically set environmental variables when files from a particular directory are executed?

开发者 https://www.devze.com 2023-01-26 06:51 出处:网络
I would like to set environmental variables in bash whenever I use a script in the ~/project/bash folder

I would like to set environmental variables in bash whenever I use a script in the ~/project/bash folder

currently, to run scripts in this folder, I have to run:

cd ~/project/bash
. ./project/bash/env.vars.sh

first, I would like these variables to be automatically set, preferably when either t开发者_如何学Che scripts are used or the user changes to ~/project or therein.

Thanks!


I am not aware of anything that will do something when a script is executed. The closest thing I can see to what you need is to put:

. ./project/bash/env.vars.sh

on the start of each of the scripts.

If that is an option for you, you can create a special user which would have the above line in its ~/.bashrc, so the environment gets set up automatically on login.

0

精彩评论

暂无评论...
验证码 换一张
取 消