Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get environment variables from within gvim

When I start gvim from withing a terminal, I can access my all environment variables.

But if I launch gvim from a menu or from the "Run application" launcher, all my environment variables are not accessible.

How can I access the environment variables defined in my bashrc if gvim is not launched from a terminal ?

These variables are defined in ~/.bashrc

Distro: Ubuntu Intrepid

Note1: the "Run application" launcher is accessible by hitting ALT+<F2>

like image 344
Toni Avatar asked May 19 '09 13:05

Toni


1 Answers

You should be able to read all of the actual environment variables, e.g.

:!echo $PATH

Your problem is with personal environment variables.

Why are you trying to read environment variables within gvim? There may be a better way of doing things.

Scope of Environment Variables
When you log in to your computer, bash sources the .bash_profile file.
When you run a terminal it sources the .bashrc file, so your personal environment variables are available within that terminal and any subshells.

Unless you're exporting the variables from your .bashrc these variables won't be available within the general environment, and they will only be available after you have run a terminal if you export them.

Since you're running gvim through an application launcher, nothing is reading your .bashrc file to create those environment variables for you.

For some info on bourne shell environment variables, see section 9.1.2

So a good place to put:

MYENVIRONMENTVARIABLE=new value of environment variable
export MYENVIRONMENTVARIABLE

is within the .bash_profile, and then if you want to make any changes to the variable, make sure you export them again (and if you want the changes to be permanent, edit the .bash_profile).

Note that the value of this environment variable will be available for any new shells, but the existing shells probably won't re-read the environment variables.

like image 112
Andy Avatar answered Sep 29 '22 01:09

Andy