Variable without value outside the script

I have a as.sh bash script:

code:

export tr="$HOME/public_html"

echo $tr

but…

agunet@agunet:~> ./as.sh
/home/agunet/public_html
agunet@agunet:~> echo $tr

agunet@agunet:~>

In the script the variable is correctly assigned. But when the script stops, $tr has no value at all.

What is wrong here ?

thanks for any feedback

agunet

Exports are only for the current process and to child processes, it doesn’t go the other way. When the child shell (as.sh) exits, the setting disappears. In other words there is no “global” environment. That’s how it is in Unix/Linux.

So if you need to set something in the current shell, you need to source the file containing the setting. E.g.

source as.sh

Then the contents of as.sh are read in the current shell.

Perhaps you might want to read up on some Unix/Linux concepts. Search for the RUTE guide.

Hi
That only works for the script life time, you need to source it rather
than run it so it’s available to the shell your running. There are a
couple of ways to achieve this. either add to your export line
in ~/.bashrc file or source it direct;


echo export tr="$HOME/public_html" > .tr
.. .tr
echo $tr


Cheers Malcolm °¿° (Linux Counter #276890)
SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.27.45-0.1-default
up 11 days 18:04, 2 users, load average: 0.12, 0.06, 0.02
GPU GeForce 8600 GTS Silent - CUDA Driver Version: 195.36.15

Perhaps you might want to read up on some Unix/Linux concepts. Search for the RUTE guide

yes, definitly.

I must read soe linux/unix concepts.

thanks 4 all

Does the site http://www.gnoppix.org exisits ? Or is just not available at the moment ?