2

On some workstations (Debian & Ubuntu) and on a server (CentOS) I need environment variables for some scripts and jobs. What I did was altering ~/.profile:

SOMEVARIABLE=/some/custom/path
...

Is this common practice? Are there any side effects I need to know about? Or is this solution fine & stable? Especially on the server I need this to work reliably.

I used ~/.profile because the scripts are always executed via job-specific users without sudo rights - so I thought user-specific environment variables would be appropriate?!

EDIT:

Since the paths differ on the machines and we're talking about more than one or two variables passing the variables as parameters to the scripts wouldn't be a nice solution and hardcoding them into the scrips would require me to update it manually for every machine. That's why I wanted environment variables.

  • Why not setting those variables directly in the script or giving the parameters as command line options? – michas Feb 13 '16 at 12:25
  • Because the paths they model are different on some of the workstations and especially on the server. So I want to read the variables in the script - otherwise I would have to manually put them in the scripts each time I have to change something (for every machine). – daniel451 Feb 13 '16 at 12:26
1

It is possible to do so, and I use it to change the default of some programs (usually in form of my default parameters).

For scripts I write I prefer to put the configuration in a separate file ~/.my_program_x.conf and do a . ~/.my_program_x.conf.

In general (AFAIK) scripts prefer to have a configuration file for such cases.

Note: I think you should prefix the variables with export, or some scripts could not see the variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.