Define a variable in the .environment file and use (refrence) that in the .sh file Define a variable in the .environment file and use (refrence) that in the .sh file shell shell

Define a variable in the .environment file and use (refrence) that in the .sh file


/etc/environment and ~/.pam_environment are read when you log in. If you've just edited those files, your changes don't apply to the current session.

If you want to apply the changes to your current session, you can run

. /etc/environment

to set the variables in your current shell. This only works if the values of the variables don't contain any shell speciavairablel characters (spaces, ()[]{}\|&;<>~*?'"`$# and I may be forgetting a few), because the syntax of /etc/environment is only an approximation of the syntax of the shell.

If you've added new variables, and not just changed their value, you'll also need to export them (VAR=value in the shell only creates a shell variable, not an environment variable).

export MY_HOME checkfolder createfolder

or more generally

export $(sed -n 's/^\([A-Za-z0-9_]*\)=.*/\1/p')

There is no file that sets the environment for every new program, because that would defeat the point of the environment, which is that every process has its own which it inherits from its parents. If there was a “global environment file”, it would make it impossible to run programs with a different environment. If you want a global configuration, read a configuration file:

if [ -e ~/.my_application_configuration.sh ]; then  . ~/.my_application_configuration.shfi

There is a way to have a file that sets the environment for every bash script (only bash scripts, not sh scripts): put the full path to the file in the environment variable BASH_ENV. As I explained just above, this is usually a bad idea.