Jump to content

how to define environment variable in a script


Guest mastemmer
 Share

Recommended Posts

Guest mastemmer

I have been using other Linux distributions for some time, but i am new to Mandriva.

I want to use a startup script such as .profile or .bashrc to define and export some

environment variables such as

 

export CVSROOT=path/to/my/cvsroot

export CVS_RSH=ssh

 

If i type this in a command line the variables are defined as expected. I can check this with

 

echo $CVSROOT

 

The trouble is that if i run these variable definitions as a shell script, they simply take no effect.

The variable definitions are not exported out of the script.

What is missing?

Link to comment
Share on other sites

For your commands to take effect, you have to source the script, not execute it. Here's the syntax:

$ . ./script.sh

The first dot can be replaced with the keyword "source".

 

It is however a good idea to place those lines in the login scripts as you suggested. Did you try the ".bash_profile" file? This should be the appropriate file if you use bash as your login shell.

 

Yves.

Link to comment
Share on other sites

Guest mastemmer

Thank you so much Yves, that is it.

Running the script as

source ./script.sh

really works.

Also placing my environment definitions in .bash_profile makes it work on startup.

 

M. Stemmer

Link to comment
Share on other sites

  • 2 weeks later...
Guest mastemmer
Not a good idea to put CVS variables in bash_profile, as if you ever need to use another CVS directory, it could cause some problems.

 

Maybe, but I had no problem using -d option to access other CVS directories.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...