Apple/Macos /usr/bin/env (used in shebang) ignores/resets the DYLD_LIBRARY_PATH variable

278 Views Asked by At

I often use the env utility in the shebang to call python2 because the location of python2 is not always the same accross systems :

/usr/local/bin/python2
/usr/bin/python2

Therefore, here is my the shebang line I use :

#!/usr/bin/env python2

My pb. is that the DYLD_LIBRARY_PATH variable gets ignored or reset by the env utility on Macos :

I have the following line in my .profile :

export DYLD_LIBRARY_PATH=$HOME/local/lib
export DUMMY=$HOME/local/lib

Let testENV.sh the following shell script :

#!/usr/bin/env bash

test $(uname -s) = Linux  && echo "=> LD_LIBRARY_PATH   = $LD_LIBRARY_PATH"
test $(uname -s) = Darwin && echo "=> DYLD_LIBRARY_PATH = $DYLD_LIBRARY_PATH"

echo "=> DUMMY = $DUMMY"

If I run ./testENV.sh on LINUX, the result is :

=> LD_LIBRARY_PATH = /users/EtuX/0123456789/local/lib
=> DUMMY = /users/EtuX/0123456789/local/lib

If I run ./testENV.sh on Macos, the result is :

=> DYLD_LIBRARY_PATH =
=> DUMMY = /Users/xyztxyzt/local/lib

If I print the DYLD_LIBRARY_PATH variable using echo from outside the script (at the bash prompt), it shows :

/Users/xyztxyzt/local/lib

INFO : My .profile is a symbolic link to .bash_profile

EDIT 2 : On Macos, the env utility seems to be the "guilty" one :

$ which env
/usr/bin/env
$ env bash testENV.sh
=> DYLD_LIBRARY_PATH =
=> DUMMY = /Users/xyztxyzt/local/lib
$ bash testENV.sh
=> DYLD_LIBRARY_PATH = /Users/xyztxyzt/local/lib
=> DUMMY = /Users/xyztxyzt/local/lib

EDIT 3 : Replaced LD_LIBRARY_PATH by DYLD_LIBRARY_PATH

EDIT 4 : Updated the testENV.sh shell script.

EDIT 5 : Updated the testENV.sh shell script with the DUMMY variable.

Is there a way to make it work ?

0

There are 0 best solutions below