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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...