Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

bash export not working for only one variable

Occasionally when I export in bash it doesn't give an error but it doesn't set the environment variable either. Here's what I mean:

This works:

bash-3.2$ export DYLD=$ABC_HOME
bash-3.2$ env | grep DYLD
DYLD=/Users/my_username/abc_home

But when I continue, these don't:

bash-3.2$ export DYLD_LIBRARY=$ABC_HOME
bash-3.2$ env | grep DYLD
DYLD=/Users/my_username/abc_home

bash-3.2$ export DYLD_L=$ABC_HOME
bash-3.2$ env | grep DYLD
DYLD=/Users/my_username/abc_home

bash-3.2$ export DYLD_=$ABC_HOME
bash-3.2$ env | grep DYLD
DYLD=/Users/my_username/abc_home

Any idea what I could look at to fix this?

FWIW, other exports with underscores work as expected, but this seems to start failing once I add the underscore in.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This appears to be an OS X protection (added in El Capitan possibly) that prevents these (potentially dangerous) environment variables from being exported to spawned processes.

This thread on the Apple Developer Forums discuss this some.

The official documentation here also documents this briefly:

Spawning children processes of processes restricted by System Integrity Protection, such as by launching a helper process in a bundle with NSTask or calling the exec(2) command, resets the Mach special ports of that child process. Any dynamic linker (dyld) environment variables, such as DYLD_LIBRARY_PATH, are purged when launching protected processes.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...