0

script file set_env:

#!/bin/bash
export LD_LIBRARY_PATH=some_path/openssl/lib/

I run it from the terminal: ./set_env

but variable is not established:

printenv | grep "LD_LIBRARY_PATH"

prints nothing.

So it should be?

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
  • 1
    You can't. A child process cannot affect the environment of its parent. – chepner Jul 21 '20 at 14:35
  • Does this answer your question? [Can I export a variable to the environment from a bash script without sourcing it?](https://stackoverflow.com/questions/16618071/can-i-export-a-variable-to-the-environment-from-a-bash-script-without-sourcing-i) – Benjamin W. Jul 21 '20 at 15:27

1 Answers1

2

A child process cannot change the environment of the parent.

The only way to do this is to have the parent environment source the script.
It's all in how your "run" it.

./set_env   # won't work creates a child process that evaporates
. ./set_env # reads the script in the *CURRENT* environment, loads the vars
Paul Hodges
  • 13,382
  • 1
  • 17
  • 36