Use shell script to add environment variables

The environment variable is set in the shell script, such as export LIBRARY_PATH=./lib/, after the script is executed, the generated executable file is executed, and an error is displayed

error while loading shared libraries: libww.so: cannot open shared object file: No such file or directory

But if you run the export sentence on the command line alone, there will be no problem after gcc compiles the code

I can't figure out why the script is executed and the environment variables are set, but running the executable file always fails.

 

The reason is that ./test.sh is used to execute the script. If source  test .sh is used, the environment variable will take effect.

When ./XXX.sh, the PATH printed in the script is changed, but the echo $PATH in the terminal does not see the change, because this execution means that it is not in the current process

So. Why is this?

The key: directly executing a script file runs in a subshell, while source runs in the current shell environment.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324098857&siteId=291194637