Q:

Unable to modify LD_CONFIG_PATH from script

I'm trying to write a script that adds some path to LD_CONFIG_PATH in order to not get "blabla.so not found".  The problem is that my script is able to modify its own context (via export) but it doesn't affect other shells.  I want to set the a variable globally so it persists between reboots and shells. 
My current script looks like:
LDPATH='/opt/mqm/lib64'
LD_LIBRARY_PATH="$LDPATH:$LD_LIBRARY_PATH"
ldconfig

which I run like 
sudo ./set_my_ld_path.sh
$LD_LIBRARY_PATH 

And it returns nothing (LD_LIBRARY_PATH is empty). 
I also tried
LDPATH='/opt/mqm/lib64' env
LD_LIBRARY_PATH="$LDPATH:$LD_LIBRARY_PATH"
ldconfig

but it only writes all my existing variables such as PATH/LANG/HOME/LC_TIME/...
For example, I can run following script in powershell and it does what I'd like to have here:
# setting an environment variable for current and descendant processes, same as bash `export`
$env:OPENCV_DIR = $OPENCV_DIR

# applying it machine-wide, persists between users/shells/reboots
[Environment]::SetEnvironmentVariable("OPENCV_DIR", $env:OPENCV_DIR, [EnvironmentVariableTarget]::Machine)

How could it be done? 

A:

First of all, assignments can not have spaces around the =. 
Secondly, you can never affect the current environment from a child process (a script). 
To run a script that sets an environment variable, and have that change affect the current environment, you will need to source the script using either . ( dot), or source in bash. 
You may also not source a script through sudo (it's unclear why you are using sudo at all in this case). 
This means that you can have a script file like this:
LD_LIBRARY_PATH="/opt/mqm/lib64:$LD_LIBRARY_PATH"

which you then source using either
.  ./file

or
source ./file

Setting (and exporting) the variable in your shell startup file for interactive shells (~/.bashrc if you use bash), would set it "globally" (for all processes started from the shell).