-1

I have the following files

  1. build.sh

    source exportpath.sh
    
  2. exportpath.sh

    export LD_LIBRARY_PATH=/usr/local/lib/
    

But,when I am executing this build.sh and then running the echo $LD_LIBRARY_PATH command I am not able to get the LD_LIBRARY_PATH value. How to set this value to the current shell.

I found that we have to source it in the current shell. But I want it done by a shell script.

When I am using source exportpath.sh in current shell, then my LD_LIBRARY_PATH is working but I want this should be done by a shell script.

How can I do this?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
pradipta
  • 1,718
  • 2
  • 13
  • 24
  • Why exactly are you asking? What is the overall goal?? – Basile Starynkevitch Dec 10 '12 at 06:37
  • possible duplicate of [Export a variable to the environment from a bash script without sourcing it](http://stackoverflow.com/questions/16618071/export-a-variable-to-the-environment-from-a-bash-script-without-sourcing-it) – tripleee Aug 25 '15 at 06:53

2 Answers2

2

There is no magical way to have an environment variable set in the child shell be propagated to the parent shell. See this reply

You could implement some convention, for instance by having exportpath.sh taking a filename, that build.sh would later source (or use eval).

You may want to have your own shell function to wrap both.

But you should usually not do such weird tricks. For example, you could wrap some of your programs into a shell script setting the LD_LIBRARY_PATH (mozilla or firefox is often doing such things).

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
-4
echo $LD_LIBRARY_PATH

Note the Use of "$" to reference the variable value.

TheRuss
  • 318
  • 3
  • 9