Alexandr Zhukov
Alexandr Zhukov

Reputation: 21

How to set enviroment variable from shell script

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?

Upvotes: 0

Views: 73

Answers (1)

Paul Hodges
Paul Hodges

Reputation: 15246

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

Upvotes: 2

Related Questions