[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: basics about env variables



29.12.2002 16:35:43, "Michael P. Soulier" <msoulier@storm.ca> wrote:
>On 29/12/02 Robert Land did speaketh:
>
>> NNTPSERVER=news.btx.dtag.de
>> export NNTPSERVER
>>
>> then did a new init and tried a echo $NNTPSERVER
>> which resulted in a blank line in response.
>>
>> What was my fault and was this actually slrnpull
>> required?
>
>    That is the correct syntax for setting environment variables in the bash
>shell, even if it can be done in one line. Your syntax is not at fault here. I
>can't speak to the other potential causes.

I second that. The syntax is correct.
What may have gone wrong is, that you have a script, in which you
set your NNTPSERVER. Then when starting this script, NNTPSERVER is set
correctly inside the script, but no longer valid after the script has finished.
This is normal behaviour. Starting a script means starting a new shell.
Variables are local to this shell - and if exported, as in your case, can
be seen from any child of this shell, but not it's parent.

If you want to experiment, try
  Write a small script in which you export a variable.
  Have an echo for this variable in the script.
  Start the script and see what happens.
  Issue the echo from the shell and see what happens.

You'll most likely ask, whether there is a way to set some variables from
a script. Yes, there is. Bash can excute a script in its own context (without
starting a subshell). Use ". scriptname" for this.

HTH, Michael

  





Reply to: